jqGrid:表单未显示复选框值

时间:2012-06-27 20:54:47

标签: jqgrid

我有以下调用加载网格:

$("#searchlist").jqGrid({
    url:'./searchlibrary',
    datatype: 'json',
    mtype: 'POST',
    postData: {
        type: function(){return $('select[name="searchtype"]').val();},
        criteria: function(){return getSearchData();}
    },
    colNames:['Resource Name','Unit', 'Topic','Document Type','Content Type','Select'],
    colModel :[ 
        {name:'resourceName', index:'resourceName', width:380, align:'left'}, 
        {name:'unit', index:'unitID', width:40, align:'center',sortable:true,
            sorttype:'text'}, 
        {name:'topic', index:'topicID', width:220, align:'center',sortable:true}, 
        {name:'docType', index:'docTypeID', width:97, align:'center',
            sortable:true}, 
        {name:'contentType', index:'contentTypeID', width:97, align:'center',
            sortable:true},
        {name: 'select', width:55, align: "center", sortable: false, editable: true,
            edittype: "checkbox", editoptions: { value:"Yes:No" },
            formatter:"checkbox",formatoptions: {disabled : false}}
    ],
    rowNum:20,
    sortname: 'resourceName',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    width:878,
    height:251
});

注意colModel部分中的最后一项。请注意editoptions部分。当网格加载时,似乎忽略了这一点。检查chrome中的元素会显示以下代码:

<input type="checkbox" value=" " offval="no">

我在宣言中做错了吗?

更新

这里返回了JSON:

 {"total":1,"page":"1","records":"4","rows":[{"id":"1","cell":["Test Resource 1","1","Topic 1","pdf","course","1"]},{"id":"2","cell":["Test Resource 2","1","Topic 1","pdf","course","2"]},{"id":"3","cell":["Test Resource 3","1","Topic 2","mp4","course","3"]},{"id":"4","cell":["Test Resource 4","1","Topic 2","wmv","course","4"]}]}

这仍然给我4个结果默认选中。这就是我现在选择的colModel中的内容:

 {name: 'select', index:'resourceID', width:55, align: "center", sortable: false, editable: true, edittype: "checkbox", editoptions: { value:"Yes:No", defaultValue:"No" }, formatter:"checkbox",formatoptions: {disabled : false}}

其中一个选择单元格的第一个生成的html是:

 <input type="checkbox" checked="checked" value="1" offval="no">

1 个答案:

答案 0 :(得分:1)

如果您在网格中加载数据,则select列的值将作为formatter:"checkbox"的复选框填充。如果值为"",则可以使用默认值。因此,可以使用defaultValue的{​​{1}}来指定默认值。 HTML片段

formatoptions
带有<input type="checkbox" value=" " offval="no"> 值的

表示您可能错误地使用了空格而不是空字符串。如果您需要正确填写数据,则需要从服务器返回包含" "truefalse10,{{1 }},yesno(所有值都不重要)。有关详细信息,请参阅the source code

因此,您应该再次验证从服务器返回的数据。我个人更喜欢使用onoff作为复选框的输入值。

相关问题