Jqgrid treegrid滚动到逐行ID,如果折叠则展开节点 [英] Jqgrid treegrid scroll to a row by row ID and expand the node if collapsed

查看:460
本文介绍了Jqgrid treegrid滚动到逐行ID,如果折叠则展开节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景是一个Jqgrid树状网格,其中所有节点都已加载,其中一些节点由于用户交互而折叠,其中一些节点已扩展. 现在需要根据行ID滚动到特定行,并且如果该行在折叠的节点内,则展开该节点,直到该行对用户可见为止. 有提示吗?

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?

推荐答案

要扩展TreeGrid的节点,可以使用expandRow.一个人应该另外做一个循环,并扩展该行的所有父级.可以使用getNodeParent获取直接父项.另外,应该使用scrollrows: true选项将网格滚动到选定的行.

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.

生成的演示允许按rowid选择行需要选择.点击按ID选择行"按钮,即可完成您需要的操作:

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

这篇关于Jqgrid treegrid滚动到逐行ID,如果折叠则展开节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆