问题
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