DOJO:LazyTreeGrid 中的延迟加载节点 - 寻找示例代码

发布于 2025-01-02 16:03:47 字数 207 浏览 0 评论 0原文

我正在寻找如何将 QueryReadStore (或其他一些商店)与 dojox.grid.LazyTreeGrid 一起使用的示例?

我希望能够显示大型结构并仅从服务器加载必要的数据。 仅应从专用服务器脚本加载开放节点的子节点。

我已经将 QueryReadStore 与 dojox.grid.DataGrid 一起使用,效果很好:)

帮助,谢谢。

I'm looking for an example of how to use QueryReadStore (or some other store) with dojox.grid.LazyTreeGrid ?

I want to be able to display big structures and load only necessary required data from server.
Only children of open nodes should be loaded from dedicated server script.

I'm already using QueryReadStore with dojox.grid.DataGrid and it works great :)

Help, Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小伙你站住 2025-01-09 16:03:47

这是基于我目前正在做的一些事情的冗长解释/示例。
这假设您对 Dojo 1.7 风格的包有基本的了解(例如,我们假设默认的 Dojo 包已正确设置)。

客户端(js 文件)

require(["dojo/ready",
    "dojox/grid/LazyTreeGridStoreModel",
    "dojox/data/QueryReadStore",
    "dojox/grid/LazyTreeGrid"], function(ready, LazyTreeGridStoreModel, QueryReadStore, LazyTreeGrid) {
        ready(function() {
            var cellLayout = [
                {name: 'Name of fruit', field: 'name', width: '300px', defaultValue: ""},
                {name: 'Color of fruit', field: 'color', width: '100px', defaultValue: ""},
                {name: 'Size of fruit', field: 'size', width: '100px', defaultValue: ""}
            ];

            // This is the url on which your server will listen for GET requests
            var dataStore = new QueryReadStore({url: "url/to/load/rows"});
            var treeModel = new LazyTreeGridStoreModel({store: dataStore, childrenAttrs: ['children'], serverStore: true});

            var grid = new LazyTreeGrid({
                treeModel: treeModel,
                structure: cellLayout,
                autoHeight: 20}, "gridContainerId"); // you need to have a DOM element by that id
            grid.startup();
        }
    });

服务器端:

您需要一个服务器端处理程序来侦听 url/to/load/rows 上的 GET 请求。这些请求最多有 3 个参数:

start    - 0-based index of the first item to return
count    - number of items to return
parentId - Id of the parent of the children items that are requested.
           Optional, not present for 1st call (because 1st-level objects have no parents).

该处理程序可以用您最喜欢的服务器端语言(即带有 ASP.Net MVC、Ruby 等的 C#)编写。

您的服务器处理程序的工作将是返回一个 json 结构,其中包含以下 3 个属性:

items       - Array containing the items you want to display.
              Each item represents a row in the grid. Each item should
              have at least some of the fields you specified in your layout
              and must have the 2 following characteristics:
                - Must have a "children" attribute. That is a bool value.
                  If true, the row is assumed to have children and will have
                  an expando left of it. The grid query the server for children when you expand it.
                  If false, the row is considered terminal, no expando is shown.

                - Must have a unique id. This will be the id that will be set in the "parentId"
                  param when querying the server for the children of that row. It must be stored
                  in the field referred to by the "identifier" attribute (see below).

identifier  - The name of the attribute of each item that contains its unique id.
numRows     - The number of total items existing on this level (not just the number of items you sent back).
              This is used to set the grid & scrollbar size and other UI things.

客户端/服务器通信

在我之前的示例的基础上,一旦网格启动(客户端),它将请求类似以下内容:

GET url/to/load/rows?start=0&count=25

服务器将返回以下内容:

{
    "items":[
        {"name": "apple", "color": "red", "size": "small", "uniqueId":"a1", "children": true},
        {"name": "watermelon", "color": "green", "size": "big", "uniqueId":"b1", "children": false}
    ],
    "identifier": "uniqueId",
    "numRows":2
}

网格将显示 2 个水果。 apple 将有一个 Expando,但没有 watermelon(由于 children 属性)。
假设用户单击 apple 展开。网格将请求其子项:

GET url/to/load/rows?parentId=a1&start=0&count=25

服务器可能返回类似以下内容:

{
    "items":[
        {"name": "mcintosh", "color": "red-green", "size": "small", "uniqueId":"a2", "children": false}
    ],
    "identifier": "uniqueId",
    "numRows":1
}

然后,网格将在 apple 行下显示一个子项。

Here is a long-winded explanation/sample based on some stuff I am currently doing.
This assumes basic comfort with Dojo 1.7-style packages (for instance, we assume the default Dojo packages are correctly set-up).

Client-side (js file)

require(["dojo/ready",
    "dojox/grid/LazyTreeGridStoreModel",
    "dojox/data/QueryReadStore",
    "dojox/grid/LazyTreeGrid"], function(ready, LazyTreeGridStoreModel, QueryReadStore, LazyTreeGrid) {
        ready(function() {
            var cellLayout = [
                {name: 'Name of fruit', field: 'name', width: '300px', defaultValue: ""},
                {name: 'Color of fruit', field: 'color', width: '100px', defaultValue: ""},
                {name: 'Size of fruit', field: 'size', width: '100px', defaultValue: ""}
            ];

            // This is the url on which your server will listen for GET requests
            var dataStore = new QueryReadStore({url: "url/to/load/rows"});
            var treeModel = new LazyTreeGridStoreModel({store: dataStore, childrenAttrs: ['children'], serverStore: true});

            var grid = new LazyTreeGrid({
                treeModel: treeModel,
                structure: cellLayout,
                autoHeight: 20}, "gridContainerId"); // you need to have a DOM element by that id
            grid.startup();
        }
    });

Server-side:

You need a server-side handler that will listen to GET requests on url/to/load/rows. Those requests will have up to 3 parameters:

start    - 0-based index of the first item to return
count    - number of items to return
parentId - Id of the parent of the children items that are requested.
           Optional, not present for 1st call (because 1st-level objects have no parents).

That handler can be written in your favorite server-side language (i.e. C# with ASP.Net MVC, Ruby, etc.)

The job of your server handler will be to return a json structure containing the following 3 attributes:

items       - Array containing the items you want to display.
              Each item represents a row in the grid. Each item should
              have at least some of the fields you specified in your layout
              and must have the 2 following characteristics:
                - Must have a "children" attribute. That is a bool value.
                  If true, the row is assumed to have children and will have
                  an expando left of it. The grid query the server for children when you expand it.
                  If false, the row is considered terminal, no expando is shown.

                - Must have a unique id. This will be the id that will be set in the "parentId"
                  param when querying the server for the children of that row. It must be stored
                  in the field referred to by the "identifier" attribute (see below).

identifier  - The name of the attribute of each item that contains its unique id.
numRows     - The number of total items existing on this level (not just the number of items you sent back).
              This is used to set the grid & scrollbar size and other UI things.

Client/Server communication

To build upon my previous example, as soon as the grid is started-up (client-side), it will request something like:

GET url/to/load/rows?start=0&count=25

The server would return the following:

{
    "items":[
        {"name": "apple", "color": "red", "size": "small", "uniqueId":"a1", "children": true},
        {"name": "watermelon", "color": "green", "size": "big", "uniqueId":"b1", "children": false}
    ],
    "identifier": "uniqueId",
    "numRows":2
}

The grid will display the 2 fruits. apple will have an expando, but not watermelon (due to the children attribute).
Assume the user clicked on the apple expando. The grid will request its children:

GET url/to/load/rows?parentId=a1&start=0&count=25

The server could return something like:

{
    "items":[
        {"name": "mcintosh", "color": "red-green", "size": "small", "uniqueId":"a2", "children": false}
    ],
    "identifier": "uniqueId",
    "numRows":1
}

The grid will then display a single child under the apple row.

孤单情人 2025-01-09 16:03:47

我想我这里有你要找的东西。一些关于将 QueryReadStore 与 dojox.grid.LazyTreeGrid 一起使用的优秀示例代码,并且也一步一步地进行了充分解释。

请参阅此处:http://livedocs.dojotoolkit.org/dojox/grid/LazyTreeGrid

我希望这能促进您的工作并能够实现您的目标。

问候

弗兰克。

I think I have what you are looking for here. Some excellent example code on using QueryReadStore with dojox.grid.LazyTreeGrid, and it's fully explained step by step too.

Please see here: http://livedocs.dojotoolkit.org/dojox/grid/LazyTreeGrid

I hope this advances your work and you are able to accomplish your goals.

Regards

Frank.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文