0

我有以下调用来加载网格:

$("#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。注意编辑选项部分。加载网格时,它似乎忽略了这一点。检查 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">
4

1 回答 1

1

如果您在网格中加载数据,则该select列的值将填充为与formatter:"checkbox". 如果值是""默认值可以使用。所以可以使用defaultValueformatoptions指定默认值。HTML 片段

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

with " "value 表明您可能使用空格而不是空字符串有错误的数据。如果您需要正确填写数据,您需要从服务器返回具有truefalse10yes、或的数据no(所有值的大小写都不重要)。有关更多详细信息,请参阅源代码onoff

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

于 2012-06-27T21:15:08.540 回答