Javascript W2UI网格:选中的复选框不保存;
我在工具栏上引入了两个按钮,一个是“CheckAll”,另一个是“UncheckAll”,它们将对网格中的特定列(如“Status”(带复选框)产生影响。为此,我编写了两个Javascript函数Javascript W2UI网格:选中的复选框不保存;,javascript,php,jquery,w2ui,Javascript,Php,Jquery,W2ui,我在工具栏上引入了两个按钮,一个是“CheckAll”,另一个是“UncheckAll”,它们将对网格中的特定列(如“Status”(带复选框)产生影响。为此,我编写了两个Javascript函数 function check_all(the_unchecked){ for(i=0; i<the_unchecked.length; i++){ the_unchecked[i].checked = true; } } function uncheck
function check_all(the_unchecked){
for(i=0; i<the_unchecked.length; i++){
the_unchecked[i].checked = true;
}
}
function uncheck_all(the_checked){
for(i=0; i<the_checked.length; i++){
the_checked[i].checked = false;
}
function check\u all(未选中的函数){
对于(i=0;i我认为最好的方法是将checkAll和uncheckAll附加到网格本身。这样使用起来更容易。我还修改了render函数以将状态保存回网格记录。因此,您可以这样添加:
{ field: 'status', caption: 'Status', size: '50px',
render: function (record) {
return '<div style="text-align: center">'+
' <input type="checkbox" ' + (record.status ? 'checked' : '') +
' onclick="var obj = w2ui[\''+ this.name + '\']; obj.get('+ record.recid +').status = this.checked;">'+
'</div>';
}
}
您可以在定义网格列时添加它。之后,您可以这样调用它:
w2ui[grid_name].checkAll();
// OR
w2ui[grid_name].uncheckAll();
但是,您需要获取所有记录ID才能将其提交到服务器,为此请使用getAllChecked。再想一想,我认为您不需要定义这些函数,因为它们很短。需要时直接调用它们即可
注意:您可以考虑使用GrID.St.StultStale= Trror。参见
checkAll: function () {
this.set({ status: true });
},
uncheckAll: function () {
this.set({ status: false });
},
getAllChecked: function () {
return this.find({ status: true });
}
w2ui[grid_name].checkAll();
// OR
w2ui[grid_name].uncheckAll();