我在剑道网格中的每一行都有一个复选框。如果用户对网格进行排序或过滤,则复选框中的复选标记会被清除。如何防止在排序或过滤发生后取消选中或重新选中复选框?请参考以下js fiddle来观察排序过程中的行为:
http://jsfiddle.net/e6shF/33/ http://jsfiddle.net/e6shF/33/
这是 jsfiddle 上的代码供参考(...需要问这个问题):
$('#grid').kendoGrid({
dataSource: { data: [{id:3, test:'row check box will unchecked upon sorting'}]},
sortable: true,
columns:[
{
field:'<input id="masterCheck" class="check" type="checkbox" /><label for="masterCheck"></label>',
template: '<input id="${id}" type="checkbox" />',
filterable: false,
width: 33,
sortable: false // may want to make this sortable later. will need to build a custom sorter.
},
{field: 'test',
sortable: true}
]});
基本上每次都会清除选择,因为网格被重新绘制。您可以将检查项存储在数组或对象中,当重新绘制网格(dataBound 事件)时,您可以将它们再次标记为已检查。
为了简化事情,这里是代码的更新版本。还可以使用 headerTemplate 选项来设置标头模板 - 不要将字段命名为模板。
var array = {};
$('#grid').kendoGrid({
dataSource: { data: [{id:3, test:'row check box will unchecked upon sorting'}]},
sortable: true,
dataBound:function(){
for(f in array){
if(array[f]){
$('#'+f).attr('checked','checked');
}
}
},
columns:[
{
headerTemplate:'<input id="masterCheck" class="check" type="checkbox" /><label for="masterCheck"></label>',
template: '<input id="${id}" type="checkbox" />',
filterable: false,
width: 33,
sortable: false // may want to make this sortable later. will need to build a custom sorter.
},
{field: 'test',
sortable: true}
]});
var grid = $('#grid').data().kendoGrid;
$('#grid tbody').on('click',':checkbox',function(){
var id = grid.dataItem($(this).closest('tr')).id;
if($(this).is(':checked')){
array[id] = true;
}else{
array[id] = false;
}
})
Link http://jsfiddle.net/e6shF/34/到小提琴
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)