Jqgrid treegrid scroll to a row by row ID and expand the node if collapsed

北战南征 提交于 2019-12-11 07:43:19

问题


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 based on the row ID, and if the row is inside a collapsed node, then expand the node till row is visible to the user. Any hints?


回答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:

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);
});


来源:https://stackoverflow.com/questions/26521226/jqgrid-treegrid-scroll-to-a-row-by-row-id-and-expand-the-node-if-collapsed

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