Skip to content Skip to sidebar Skip to footer

Jqgrid Treegrid Scroll To A Row By Row Id And Expand The Node If Collapsed

Scenario is a Jqgrid treegrid with all nodes loaded, some of them collapsed some of them expanded as a result of user interaction. Now there is a need to scroll to a specific row

Solution 1:

To expand the nodes of the TreeGrid you can use expandRow. One should additionally make a loop and expand all parents of the row. One can use getNodeParent to get direct parent. Additionally one should use scrollrows: true option to scroll the grid to selected row.

The resulting demo allows to choose the row by rowid which need be selected. Clicking on "Select row by id" button do what you need:

enter image description here

Click event handle which I used in the demo you will see below

$("#selectId").button().click(function () {
    var idToSelect = $("#selectedId").val(), // id of the row which need be selected
        localRowData = $grid.jqGrid("getLocalRow", idToSelect);

    while (localRowData.parent !== null && localRowData.parent.toUpperCase() !== "NULL") {
        localRowData = $grid.jqGrid("getNodeParent", localRowData);
        $grid.jqGrid("expandRow", localRowData);
    }

    // we use scrollrows: true option so the selection below// will scroll the grid to the selected row additionally
    $grid.jqGrid("setSelection", idToSelect);
});

Post a Comment for "Jqgrid Treegrid Scroll To A Row By Row Id And Expand The Node If Collapsed"