2

We are currently having a difficult time trying to auto expand a jqGrid treegrid to the 3rd level of the tree so that all children are visible. The current data set is thousands or rows deep and we were forced to dynamically load each node when requested to be expanded, which requires reloading the grid. Expanded node ids are saved in an array as a saved tree state so that the nodes can be re-expanded when the tree is redisplayed. This goes through the process of loading each node from the database as the expansion happens. AS each node is dynamically loaded and expended gridComplete and loadComplete events are handled as expected.

We are trying to trigger the 3rd level expansion by utilizing the save tree state and the existing logic to break out the tree appropriately within the existing logic. The problem we are experiencing is that the tree cannot expand out fast enough in order to be processed, and we can never break the tree apart completely.

Here is the function to iterate through the parents to capture the appropriate ids to expand:

function ExpandGridLevel(level) {
        if (ExpandGridLevels == false) {
            ExpandTotalLevels = level; 
            ExpandLevelCurrent = 0;
            ExpandGridLevels = true;
        }

        if (!TreeExpandState) {
            TreeExpandState = new Array();
        }
        $(".treeclick", "#Grid").each(function () {
            if ($(this).hasClass("tree-plus")) {
                var id = $(this).parents("tr").attr("id");
                var rowLevel = $("#MaGrid").getLocalRow(id);
                if (rowLevel.level ==  ExpandLevelCurrent) {
                    TreeExpandState.push(id);
                    $(this).removeClass("tree-plus");
                    $(this).addClass("tree-minus");
                }
            }
        });


        $(this).trigger("reloadGrid");
        $("#Grid").jqGrid("setGridParam", { datatype: "local" });

        ExpandLevelCurrent++;
        RefreshGrid();
    }

Our gridComplete and loadComplete sections of code:

loadComplete: function (data) {                
                $("#Grid").jqGrid("setGridParam", { datatype: "local" });

                if (TreeExpandState.length == 0) {
                          setTimeout(function () { ExpandGridLevel (ExpandTotalLevels); }, 3000);
                }
}

gridComplete: function () {
                if (TreeExpandState) {

                    var rowId =  TreeExpandState.shift();
                    ExpandNode(rowId);
                }
 }

Is what we are trying to do possible with jqGrid? If so, how do we know when the tree expansion is truly complete and we can reiterate over the expended grid to begin the expansion of the next level of parents?

mservais
  • 570
  • 1
  • 7
  • 20

0 Answers0