0

I am using the kendo UI Web Grid to display some data. Since I am dealing with a lot of data I have decided to use the grid virtual scrolling feature, which works great.

Now, I need to add a non databound column that will get populated with a checkbox, so that I can check/uncheck a record in the grid for further processing.

I cam able to add the checkbox column by simply using a template :

columns: [
            {
                field: "",
                width:'3%',
                title: " ",
                hidden: false,
                template: "<input type=\"checkbox\" />"
            },

The problem that I am running into is that when virtual scrolling is enabled, if I check one of the checkboxes, then scroll the grid, when I go back to the record that was checked, it is not checked anymore.

How can I use virtual scrolling and still keep my checkbox checked ?

Thanks

4

1 回答 1

2

当您传递与 pageSize 一样多的记录时,总是会重新创建行。但是,如果您确实将该复选框绑定到底层模型,则更改将被保留,并且一旦您返回同一页面,您将看到已选中的项目。

使复选框反映模型更改的一种方法如下:

grid.tbody.on('click',':checkbox',function(e){
  var row = $(this).closest('tr');
  grid.dataItem(row).set('isAdmin',$(this).is(':checked'));

})

其中 isAdmin 是复选框绑定到的字段的名称。

是活生生的例子。

于 2013-05-07T20:02:32.760 回答