Question

I have a basic treegrid with 2 levels, and I want some rows hidden and others visible; I do this with $("#" + rowId).hide() and $("#" + rowId).show() programatically, as which rows are visible is dependent on data outside the grid. That part works fine.

However, when I collapse a node and then expand it, all children are visible, even those I hid. Evidently, jqGrid is pretty much just doing .hide() and .show() on the rows, which negates my settings. So my thought is to add a hidden field in each row that stores whether it should be visible or not, and then re-hide/show after the expand event. The problem is, I'm not sure how to catch the event and execute code immediately after it.

Oleg shows a method for catching the events here: jqGrid treeGrid catch expand collaps events

Unfortunately, that doesn't work for me because it will just override whatever hide/show I do there. I need to execute code after the jqGrid functions. Any ideas on how to do this?

Was it helpful?

Solution

The solution seems very easy for me. One need just make small modification from the code from the answer which you reference. You can do something like the following

var orgExpandNode = $.fn.jqGrid.expandNode;
$.jgrid.extend({
    expandNode: function (rc) {
        // here you can insert the code which will be executed
        // before the original expandNode
        var res = orgExpandNode.call(this, rc);

        // now you can execute some code after the original expandNode
        // for example the next line hide the node in the grid
        $("#1_1_1").hide(); // hide some row of the grid

        return res; // return the value from expandNode
    }
});

see the demo. The demo has one node in the TreeGrid which has id="1_1_1", but it stay hidden all the time.

UPDATED: Free jqGrid have beforeExpandRow, afterExpandRow, beforeExpandNode and afterExpandNode callbacks and "jqGridTreeGridBeforeExpandRow", "jqGridTreeGridAfterExpandRow", "jqGridTreeGridBeforeExpandNode", "jqGridTreeGridAfterExpandNode" events. Thus subclassing of TreeGrid methods described above is not required in case of usage free jqGrid.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top