【发布时间】:2019-05-02 21:42:03
【问题描述】:
我有一个表单,它使用jqGrid 作为表单的一部分。此部分显示可以通过复选框选择的用户信息。在评论页面上有一个编辑表单的选项,我试图在此过程中保留复选框选择。
我正在尝试为此使用window.localStorage,但是我不确定如何正确设置项目。我在 loadComplete 中调用 getItem ,我的编码在这里也可能不太正确。我现在所拥有的,当用户进行编辑时,选择 jqGrid 中的第一个项目而不是实际保存的项目。我猜是因为我没有正确设置项目。谁能提供指导?
$.jgrid.gridUnload("#list");
myGrid = $("#list").jqGrid({
url: baseURL + '/scripts/get_user_list.php' + urlString,
datatype: "json",
mtype: 'POST',
width: 660,
height: '100%',
pager: '#pager',
rowNum: 10,
rowList: [20, 30, 40, 50, 60],
sortname: 'id',
sortorder: "asc",
viewrecords: true,
multiselect: true,
repeatitems: false,
imgpath: '/scripts/jquery-ui/images',
colNames: ['id', 'Building', 'Company ID', 'Description', 'Individual Name', 'SECCode'],
colModel: [
{name: 'id', index: 'id', jsonmap: 'id', hidden: true, width: 20},
{name: 'Building', index: 'Building', jsonmap: 'Building', hidden: true, width: 20},
{name: 'CompanyId', index: 'CompanyId', jsonmap: 'CompanyId', width: 110},
{name: 'Description', index: 'Description', jsonmap: 'Description', sortable: true, width: 300},
{name: 'IndName', index: 'IndName', jsonmap: 'IndName', width: 200},
{name: 'UsrNum', hidden: true, index: 'UsrNum', jsonmap: 'UsrNum'}
],
jsonReader: {
repeatitems: false,
root: 'rows',
id: '0',
cell: '',
subgrid: {
root: 'rows',
id: '0',
cell: '',
repeatitems: false
}
},
// subgrid support
subGrid: true,
subGridUrl: baseURL + '/scripts/get_user_list.php' + urlString,
subGridModel: [{
name: ['Date', 'ID'],
params: ['CompanyId'],
align: ['center', 'right'],
width: [150, 80]
}
],
ondblClickRow: function (id) {
$('#recId').val(id);
},
beforeRequest: function () {
blnGridLoading = true;
// console.log("beforeRequest(); setting blnGridLoading=true");
fnValidateAccount(); // Check that user has data available
},
loadComplete: function () {
$(':checkbox').each(function () {
var status = localStorage.getItem(this.id) === "false" ? false : true;
$(this).prop("checked", status);
});
blnGridLoading = false;
// console.log("loadcomplete(); setting
blnGridLoading = false;
// ");
for (swap in arySwap) {
if (typeof arySwap[swap]['CompanyId'] != 'undefined') {
$("#list").jqGrid('setSelection', arySwap[swap]['CompanyId']); // select companyId
}
}
fnValidateAccount(); // Check that user has data available
},
});
这是 loadComplate 中的 localStorage.getItem,与其余代码隔离:
$(':checkbox').each(function () {
var status = localStorage.getItem(this.id) === "false" ? false : true;
$(this).prop("checked", status);
});
这是我为 setItem 尝试的内容,但我不确定将其放置在哪里,或者这是否是正确的方法。
$(':checkbox').on('change', function () {
//set the check value of checkbox
localStorage.setItem(this.id, this.checked);
});
【问题讨论】:
-
使用哪个版本的 jqGrid - Guriddo jqGrid、free-jqGrid 或 jqGrid 版本
-
5.0.1 是版本号
-
用什么编辑模块? - 从导航器编辑 jqGrid 表单或使用自定义表单编辑记录。我你用jqGird表单编辑请贴代码进行编辑。
-
这是一个自定义表单。编辑按钮从会话中调用数据库中的值。除了 jqGrid 中的值外,所有其他值都被正确调用。该表单由 3 个文本字段、2 个下拉菜单和一个填充在 jqGrid 中的列表组成。
-
你能添加一个 jsfiddle 或 sn-p 以便我们测试这段代码吗?
标签: javascript jquery jqgrid local-storage