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

Scharlotte picture Scharlotte · Dec 26, 2010 · Viewed 9.8k times · Source

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?

Answer

Oleg picture Oleg · Dec 27, 2010

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: alt text (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.