Hide expand/collapse symbol or deactivate spec. rows in jqGrid subgrid

ぐ巨炮叔叔 提交于 2019-11-26 08:26:40

问题


I have a grid with a subgrid: Only the first row of the Main grid need to have a subgrid.

The solutions I found by Google and http://www.trirand.com/....i:subgrid&s[]=hidecol doesn\'t work.

Is there a quick and dirty (hard coded) solution?


回答1:


Hiding the 'subgrid' column with jQuery("#grid_id").hideCol('subgrid'); remove full column which can be used to expand or collapse the subgrid, so you can not use the way in your case.

I suggest you to clear contain of the 'subgrid' column and unbind the 'click' event for the cells inside of loadComplete event handle:

loadComplete: function() {
    $("td.sgcollapsed:not(:first)","#list").unbind('click').html('');
}

you will have the following results:

(You can see the corresponding example live here). It's important to understand, that the loadComplete event will be called on any page, so on the second page you will have subrgid also only on the first row.

If you need to implement more complex logic in choosing of the rows which need have subgrids you can use following code

loadComplete: function() {
    var grid = $("#list");
    var subGridCells = $("td.sgcollapsed",grid[0]);
    $.each(subGridCells,function(i,value){
        if (i!==0) {
            $(value).unbind('click').html('');
        }
    });
}

The code above do the same as the statement $("td.sgcollapsed:not(:first)","#list").unbind('click').html(''), but you can easy modify the last version of the code to implement more complex behavior.

UPDATED: If you need detractive subgrid only for some row identified by the rowid you can use

$("#"+rowid+" td.sgcollapsed",grid[0]).unbind('click').html('');

(see live here) inside of the loadComplete. If you need deactivate subgrid for all rows which id is not equal to rowid you can make something like following

$('td.sgcollapsed:not("#'+rowid+' td.sgcollapsed")',grid[0]).unbind('click').html('');

(see live here)

UPDATED: free jqGrid now have new feature described in the answer: hasSubgrid callback which can be specified in subGridOptions. It allows to inform jqGrid which rows should don't have subgrids.



来源:https://stackoverflow.com/questions/4534011/hide-expand-collapse-symbol-or-deactivate-spec-rows-in-jqgrid-subgrid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!