2011-02-13 37 views
1

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

。这可能是:

  1. 复选框列表
  2. 选择列表与复选框,所以你可以比一个选择更多。

这是可能的jqGrid吗?

回答

2

jqGrid支持多选编辑。它不使用ceckboxes进行选择,而是多选select元素。我通过双击内联编辑创建了the demoenter image description here

下面是相应的代码:

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' 
    }); 
}); 

顺便说创造the demo过程中我发现,一个人不能使用具有“0”的ID,这是不完全支持的选择元素。例如,'1:运动; 2:科学'的作品,但不是'0:运动; 1:科学'。在“运动”项目的选择不会被保存的情况下。

如果您需要使用带有复选框的更舒适的控制台,则必须实施custom editing的行为。

+0

@Oleg - 谢谢你。我的问题是我的列表很长(大约100项),所以上面的解决方案是一个难以跟踪的UI,比如在表中显示复选框列表。 – leora 2011-02-13 17:45:26