How I can set and get template columns value/text in kendo Grid

Hasibul picture Hasibul · Apr 17, 2013 · Viewed 15.2k times · Source

Consider I have a kendo grid like following
http://jsbin.com/uxumab/1/

It has ItemId, Qty, Price and Total(template) column. I want to make Qty column editable and want to change total column value with the change of Qty column. Finally I want to retrieve all the values with new changes using iteration through grid.

Answer

Petur Subev picture Petur Subev · Apr 17, 2013

Basically the easiest way would be to do this through the MVVM of kendo. Here is an example:

    $(document).ready(function () {
        var gridData = [
              { ItemId: "1001", Qty: 2, price: 200 }
            , { ItemId: "1002", Qty: 1, price: 100 }
            , { ItemId: "1003", Qty: 1, price: 150 }
                     ];

        $("#grid").kendoGrid({
            dataSource: gridData
            , selectable: "row",
          dataBound:function(){
          grid = this;
            grid.tbody.find('tr').each(function(){            
             var item = grid.dataItem(this);
             kendo.bind(this,item);
         })
          }
            , columns: [
                  { field: "ItemId" }
                , { field: "Qty" }
                , { field: "price" }
              , { title: "Quantity", width: "200", template: '<input data-role="numerictextbox" data-bind="value:Qty" data-max-value="100"/>' }                  , {
                     title: "Total"
                    , template: "#=Qty*price#"
                }
            ]
        });



    });

And live version.