Kendo grid cell editing

I want to manually edit the cell and based on the entered data automatically display the contents in another cell.

For example: If the quantity is changed, Total should be calculated (price * quantity) and display the result in the column Total

enter image description here

Can I use a Kendo grid? Any help was appreciated.

+4
source share
2 answers

Yes it is possible. You can find some information on the Internet if you are looking for the "KendoUI grid calculation field".

( "", "incell" "popup" ). , , incell. save .

DataSource :

var ds = {
    data    : [
        { Id: 1, ItemName: "Galaxy", Price: "25000", Qty: 2, Total: 50000 },
        { Id: 1, ItemName: "Lumia", Price: "18000", Qty: 1, Total: 18000 },
        { Id: 1, ItemName: "Experia", Price: "10000", Qty: 3, Total: 30000 } 
    ],
    schema  : {
        model: {
            id : "Id",
            fields: {
                Id       : { type: 'number' },
                ItemName : { type: 'string' },
                Price    : { type: 'number' },
                Qty      : { type: 'number' },
                Total    : { type: 'number', editable: false }
            }
        }
    }
};

:

var grid = $("#grid").kendoGrid({
    dataSource: ds,
    editable  : "incell",
    pageable  : false,
    columns   :
    [
        { field: "ItemName", title: "Item Name" },
        { field: "Price", title: "Price" },
        { field: "Qty", title: "Qty" },
        { field: "Total", title: "Total" }
    ]
}).data("kendoGrid");

Grid - save, , e.values ( e - , save), Total set .

    save : function (e) {
        if (e.values && (e.values.Qty || e.values.Price)) {
            var qty = e.values.Qty || e.model.Qty;
            var price = e.values.Price || e.model.Price;
            e.model.set("Total", price * qty);
        }
    }

: http://jsfiddle.net/qA8QX/

+7

kendo MVC, :

 @(Html.Kendo().Grid<Model>()
                  .Columns(columns =>
                  {
                      columns.Bound(p => p.ItemName);
                      columns.Bound(p => p.Qty);
                      columns.Bound(p => p.Price);
                      columns.Bound(p => p.Total);

                      columns.Command(command =>
                      {
                          command.Edit();
                      })

                  })
                  .Editable(editable => editable.Mode(GridEditMode.InLine))

                  .DataSource(dataSource => dataSource 
                      .Ajax()
                      .Model(model =>
                      {
                          model.Id(x => x.ExchangeRateId);
                          model.Field(x => x.Total).Editable(false);

                      })
                      .Read(read => read.Action("Read", "Products"))
                      .Update(update => update.Action("Update", "Products"))
                 )
            )

- :

public class Productscontroller {
public ActionResult Read([DataSourceRequest]DataSourceRequest request)
        {
        var products = proxy.GetProducts();

        DataSourceResult result = products.ToDataSourceResult(request, ProductsModel => new ProductsModel()
        {
            id = products.id,
            ItemName= products.ItemName,
            Qty= products.Qty,
            Price = products.Price,
            total = products.Qty * products.Price
        });
        return Json(result, JsonRequestBehavior.AllowGet);
    }
public ActionResult Update([DataSourceRequest]DataSourceRequest request, ProductsModel product)
        {
        var products = proxy.GetProductById(product.Id);

        Proxy<Products>.Update(products);
    }
}

,

0

Source: https://habr.com/ru/post/1532947/


All Articles