对jqGrid进行排序时,将复选框的选中状态保留在自定义格式的列中 [英] Keep checked state of checkbox in custom formatted column when sorting jqGrid

查看:241
本文介绍了对jqGrid进行排序时,将复选框的选中状态保留在自定义格式的列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加载一次的jqgrid,它使用自定义格式化程序来显示布尔值的复选框,这些布尔值在单击保存按钮时仅仅保留.但是,每当单击排序时,所有复选框的选中状态都不会保留.

I have a load once jqgrid that uses a custom formatter to display checkboxes for bool values that are persisted only when a save button is clicked. However, whenever a sort is clicked the checked state of all the checkboxes is not kept.

jQuery("#list2").jqGrid({
    url:myurl,
    datatype: "json",
    loadonce: true,
    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {name:'id',index:'id', width:55},
        {name:'isChecked',index:'isChecked', width:90, formatter:chkFmatter},
        {name:'name',index:'name asc, invdate', width:100},
        {name:'amount',index:'amount', width:80, align:"right"},
        {name:'tax',index:'tax', width:80, align:"right"},      
        {name:'total',index:'total', width:80,align:"right"},       
        {name:'note',index:'note', width:150, sortable:false}       
    ],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#pager2',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"JSON Example"
});
jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});

function chkFmatter(cellvalue, options, rowObject) {
    // do something here to format column
    return new_format_value
}

无论如何,我可以保留排序,分页等操作时单击的复选框吗?

Is there anyway that I can keep what checkboxes were clicked when sorting, paging, etc.?

推荐答案

这是因为绑定到网格的数据没有更新,因此任何新请求(分页,排序等)都将反映原始状态属性绑定到的位置.最好的选择是在复选框状态更改以更新实际数据以反映此情况时.

It is because the data that is bound to the grid is not being updated, so any new requests (paging, sorting, etc.) will reflect the original state that the property was bound to. Your best bet would be anytime the state of the checkbox changes to update the actual data to reflect this.

您可以使用 getGridParam <检索绑定到网格的数据. /a>:

You can retrieve the data that is bound to the grid using getGridParam:

var data = $('#' + gridid).jqGrid('getGridParam', 'data');

然后使用您的行ID,列名和值更新数据来更新它:

Then to update it use your rowid, name of the column, and value to update the data object:

data[row - 1][columnname] = value;

这篇关于对jqGrid进行排序时,将复选框的选中状态保留在自定义格式的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆