2

I'm using jqGrid and I can't have 2 subgrids at the same time, if the second one is clicked, the previous one should be closed.

And I can't find an event to prevent this... I need something like:

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

Maybe It's something I'm missing...

enter image description here

Thanks in advance!

4

3 回答 3

3

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

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

希望它可以帮助别人!

于 2013-09-12T19:02:40.340 回答
2

从这里子网格/事件

subGridRowExpanded: function(subgrid_id, row_id) { ... }你一起可以赶上事件。

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

您可以折叠所有展开的 subgridrow。

于 2013-09-12T19:09:57.893 回答
0

我尝试了 Luis 建议的解决方案,但没有奏效

这个工作就像一个魅力: 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);
  }
},
于 2015-04-11T02:25:44.577 回答