1

我仍在尝试找出是否可以在jqGrid中有一个单元格,并且当我拉出该行的编辑表单时,我需要一个可以将该列显示为多选列表的 GUI。

这可能是:

  1. 复选框列表
  2. 选择带有复选框的列表,以便您可以选择多个。

这在 jqGrid 中可能吗?

4

1 回答 1

3

jqGrid 支持多选编辑。它不使用复选框进行选择,而是使用多选选择元素。我在双击时使用内联编辑 制作了演示。在此处输入图像描述

下面是对应的代码:

jQuery(document).ready(function() {
    var lastSel, mydata = [
        {id:0, Name:"Lukas Podolski",     Category:"1", Subcategory:"1"},
        {id:1, Name:"Michael Schumacher", Category:"1", Subcategory:"2"},
        {id:2, Name:"Albert Einstein",    Category:"2", Subcategory:"3,4"},
        {id:3, Name:"Blaise Pascal",      Category:"2", Subcategory:"4"}
    ], grid = jQuery("#list");
    grid.jqGrid({
        data: mydata,
        datatype: 'local',
        colModel: [
            { name: 'Name', index: 'Name', width: 130, editable: true },
            {
                name: 'Category', index: 'Category', width: 100,
                formatter:'select', editable: true, edittype:'select',
                editoptions: {
                    value: '1:sport;2:science',
                    multiple: true,
                    size: 2
                }
            },
            {
                name: 'Subcategory', index: 'Subcategory', width: 250,
                formatter:'select', editable:true, edittype:'select',
                editoptions: {
                    value: '1:football;2:formula 1;3:physics;4:mathematics',
                    multiple: true,
                    size: 4
                }
            }
        ],
        sortname: 'Name',
        viewrecords: true,
        rownumbers: true,
        sortorder: 'desc',
        pager: '#pager',
        height: '100%',
        editurl: 'clientArray',
        ondblClickRow: function(rowid) {
            jQuery(this).jqGrid('editRow', rowid, true, null, null, 'clientArray');
        },
        onSelectRow: function(id){
            if (id && id!==lastSel){
                jQuery(this).restoreRow(lastSel);
                lastSel=id;
            }
        },
        caption: 'Selects with multiselect'
    });
});

顺便说一句,在创建演示期间我发现,不能使用选择元素具有“0”作为 id,这不是完全支持的。例如,“1:sport;2:science”有效,但“0:sport;1:science”无效。在这种情况下,“运动”项目的选择将不会被保存。

如果您需要使用更舒适的带有复选框的控件,则必须实现与自定义编辑相关的行为。

于 2011-02-13T17:34:29.223 回答