How to dynamically change values ​​in the kendo ui grid

I am using kendo ui grid. In that I used batch mode to save values. If I changed the record in one row, then the value with the corresponding row will also be changed, and when we click on save, both fields will be saved in the database.

For example, I have a grid like:

  Integer    Value
   1         First
   2         Second
   3         Third
   4         Fourth

If I change the value from 1 to 4, then the value 4 will change, and the values ​​will also change dynamically. I mean, I want to exchange 1 and 4 here. And also I can change the remaining fields are also saved, but finally, all records must be saved in the database. I tried both

This code will be in the grid change function

 var grid = $('#grid').data("kendoGrid");
 var selectedRow = grid.select();
 var selectedRowIndex = selectedRow.index();
 console.log(selectedRowIndex);

 var firstItem = dataSource.data()[selectedRowIndex];

 var datalength = dataSource.data();
 for (var i = 0; i < datalength.length; i++)
   {
     var dataItem = datalength[i].id;
     if (dataItem == firstItem.get('id'))
       {                                
         var secondItem = dataSource.data()[i];                                
         secondItem.set('id', dataItem);                               
       }
   }

Then the values ​​change, but the values ​​do not go to the controller after changing it.

+5
2

, , .

 dataSource.data()[changedIndex].dirty = true;
 dataSource.sync();
+7

Kendo.

$( "# my_grid" ). data ( "kendoGrid" ). dataSource.data() [rowindex].columnName = newValue;

Kendo = fclty_cd .

:

 function onChange(e) {
    var fromContactNumber = parseFloat($('#fromContactNumber').val());
    var toContactNumber = parseFloat($('#toContactNumber').val());
    var length = $('#grid table tr[role=row]').length;
    var faculty = $('#ddl_Faculty').val();
    for (var i = 1; i < length; i++) {
        var num = parseFloat($($('#grid table tr[role=row]')[i]).find("td")[4].innerText);
        if (num >= fromContactNumber && num <= toContactNumber) {
            $("#grid").data("kendoGrid").dataSource.data()[i - 1].fclty_cd = faculty;
            $($($('#grid table tr[role=row]')[i]).find("td")[11]).text(faculty);
        }
    }
}

:  $ ($ ($ ('# grid table tr [role = row]') [i]). find ( "td" ) [11]). text ();

Kendo: $ ( "# my_grid" ). data ( "kendoGrid" ). dataSource.data() [rowindex].columnName = newValue;

0
source

All Articles