jqGrid,当时只显示一个子网格

时间:2013-09-12 16:40:53

标签: jqgrid subgrid

我正在使用jqGrid,我不能同时拥有2个子网格,如果单击第二个子网格,则应关闭前一个子网格。

我无法找到阻止此事件的事件...... 我需要这样的东西:

$("#list2").jqGrid({
        multiSubGrids: false
});

也许这是我想念的东西......

enter image description here

提前致谢!

3 个答案:

答案 0 :(得分:2)

我找到了这种方式......它有效,但我不知道它是否是最好的方式:

// this will save the rowId of the previous subGrid
var previousRowId = 0;

$("#list2").jqGrid({
    // all your default mapping here..  
    ...
    subGridRowExpanded: function (subgrid_id, row_id) {
    if (previousRowId != 0) {
        $(this).collapseSubGridRow(previousRowId);
    }   
    ...
    // all your subgrid code here
    ...
    // this will save the actual row_id,
    // so the next time a subgrid is going to be expanded,
    // it will close the previous one
    previousRowId = row_id; 
});

希望它可以帮助别人!

答案 1 :(得分:2)

从这里Subgrid/Events

subGridRowExpanded: function(subgrid_id, row_id) { ... }你可以抓住这个事件。

$("#list2 tr:has(.sgexpanded)").each(function () {
    num = $(this).attr('id');
    $(this).collapseSubGridRow(num);
});

你可以折叠所有展开的子网格。

答案 2 :(得分:0)

我尝试过路易斯建议的解决方案,但它没有工作

这个就像一个魅力: http://guriddo.net/?topic=how-do-i-only-have-only-1-subgrid-expanded-at-any-time/#post-115123

subGridBeforeExpand: function(divid, rowid) {
  // #grid is the id of the grid
  var expanded = jQuery("td.sgexpanded", "#grid")[0];
  if(expanded) {
    setTimeout(function(){
        $(expanded).trigger("click");
    }, 100);
  }
},
相关问题