我为我的网格定义了内联编辑,其中包含一些复选框列,并且工作正常
我将'navGrid'
选项设置为edit: true
,我得到了漂亮的铅笔图标,当我按下它时会打开一个表单。
问题是 - 我定义了列的value属性,如下所示:value: 'true:false'
,适用于内联编辑(生成的输入元素:
<input type="checkbox" disabled="disabled" offval="no" value="false">
),
但在表单编辑模式下,生成的输入为:
<input id="isadministrator" class="FormElement" type="checkbox" checked="" value="true:false" offval="false" name="isadministrator" role="checkbox">
导致选中的值作为'true:false'发布到服务器 有任何想法吗? 附件是我的整个网格代码:
$("#grid").jqGrid({
url: 'SampleScriptService.asmx/GetGridData',
datatype: 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
//with ASP.Net services, all parameters must be set in the post request.
//so here we make sure that all the parameters that the web service expects are prensent. if not- we create them with null value.
if (!postData.username) {
postData.username = null;
}
if (!postData.fullname) {
postData.fullname = null;
}
if (!postData.isadministrator) {
postData.isadministrator = null;
}
return JSON.stringify(postData);
},
mtype: "POST",
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", records: "d.records", total: "d.total" },
colNames: ['Username', 'Full Name', 'Administrator?', 'Password'],
colModel: [
{ name: 'username', key: true, index: 'username', jsonmap: 'Username',
editable:false , edittype:'text'
},
{ name: 'fullname', index: 'fullname', /* width: 90,*/
editable:true, edittype:'text',
jsonmap: 'FullName' },
{ name: 'isadministrator', index: 'isadministrator', formatter: 'checkbox', sortable: false,
editable: true, edittype: 'checkbox', editoptions: { value: 'true:false' },
stype: 'select', searchoptions: { value: 'none:All;true:Yes;false:No' }
/*, width: 80*/, jsonmap: 'IsAdministrator' },
{ name: 'password', index: 'password'
/*, width: 150*/,
editable: true, edittype: 'password',
formatter: function (cellvalue, options, rowObject) {
//never display anything in the password column
return '';
},
jsonmap: 'Password', search: false }
],
rowNum: 2,
pager: '#pager',
viewrecords: true,
sortname: 'username',
caption: "Users Management",
onSelectRow: function (id) {
if (id && id !== currentlyEditedRowId) {
jQuery('#grid').restoreRow(currentlyEditedRowId);
currentlyEditedRowId = id;
}
jQuery('#grid').editRow(currentlyEditedRowId, true);
},
editurl: "SampleScriptService.asmx/UpdateUser"
}).jqGrid('navGrid', "#pager", { edit: true, add: true, del: false, search: false })
//add toolbar searching
.jqGrid('filterToolbar', {});
答案 0 :(得分:0)
不是你问题的答案,实际上只是一种解决方法,
我也遇到了复选框发送1:0作为检查时的值的问题。
而是我恢复使用下拉列表,并且运行正常:
{
name:'active_mdt',
index:'active_mdt',
width:20,
align:"left",
sortable:true,
editable:true,
edittype:"select",
editoptions: {value:{'1':'Active','0':'Hidden'}},
search:true,//
stype:'select',
searchoptions:{value:{'':'All','1':'Active','0':'Hidden'}}
}], search : {
caption: "Search...",
Find: "Find",
Reset: "Reset",
matchText: " match",
rulesText: " rules"
},
答案 1 :(得分:0)
@Dizzy Bryan High提出了一个非常合理的解决方法
因为我不想放弃复选框,所以我最终只在服务器端实现了JQgridParseBool()
方法,该方法处理发送的错误值。
是的,这很难看,但我找不到任何其他办法。