如何动态更改kendo ui网格中的值?

时间:2022-09-28 10:10:49

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

我正在使用kendo ui网格。在这里,我使用了批处理模式来保存值。如果我在一行中更改记录,那么具有相应行的值也将被更改,当我们单击save时,两个字段将被保存到数据库中。

For eg. I am having a grid like:

如。我有这样一个网格:

  Integer    Value
   1         First
   2         Second
   3         Third
   4         Fourth

If i change the value of 1 to 4 then the 4 will be changed and the values also changed dynamically. What i mean is i want to interchange 1 and 4 here. And also i can change remaining all fields also but finally all the records must be saved to the database. I have tried like

如果我将1的值更改为4,那么4将被更改,值也将动态更改。我的意思是我想在这里交换1和4。我还可以修改所有字段,但最后所有记录都必须保存到数据库中。我一直喜欢

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 are changing but the values are not passing to the controller after it has been changing.

然后,值在变化,但在变化之后,值不会传递给控制器。

2 个解决方案

#1


7  

If you want to play with the data directly you need to mark the records you changes as dirty.

如果您想直接使用数据,则需要将更改的记录标记为dirty。

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

#2


0  

Simply set the value of data from the Kendo grid.

只需设置来自Kendo网格的数据的值。

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

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

In my project I changed the value of my Kendo grid row with column name = fclty_cd on a dropdown change.

在我的项目中,我在一个下拉更改中使用列名= fclty_cd更改了Kendo网格行的值。

I wrote this :

我写这个:

 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);
        }
    }
}

This line changes the UI value only : $($($('#grid table tr[role=row]')[i]).find("td")[11]).text(faculty);

这一行只更改UI值:$($('#grid table tr[role=row]]')[i] .find("td")[11]).text(教员);

This line changes the value inside Kendo data grid : $("#my_grid").data("kendoGrid").dataSource.data()[rowindex].columnName= newValue;

这一行更改Kendo数据网格中的值:$(“my_grid”).data(“kendoGrid”). datasource .data() ()[rowindex]。columnName = newValue;

#1


7  

If you want to play with the data directly you need to mark the records you changes as dirty.

如果您想直接使用数据,则需要将更改的记录标记为dirty。

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

#2


0  

Simply set the value of data from the Kendo grid.

只需设置来自Kendo网格的数据的值。

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

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

In my project I changed the value of my Kendo grid row with column name = fclty_cd on a dropdown change.

在我的项目中,我在一个下拉更改中使用列名= fclty_cd更改了Kendo网格行的值。

I wrote this :

我写这个:

 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);
        }
    }
}

This line changes the UI value only : $($($('#grid table tr[role=row]')[i]).find("td")[11]).text(faculty);

这一行只更改UI值:$($('#grid table tr[role=row]]')[i] .find("td")[11]).text(教员);

This line changes the value inside Kendo data grid : $("#my_grid").data("kendoGrid").dataSource.data()[rowindex].columnName= newValue;

这一行更改Kendo数据网格中的值:$(“my_grid”).data(“kendoGrid”). datasource .data() ()[rowindex]。columnName = newValue;