質問

So I'm a first time user of dgrid, and I'm currently building my tree grid like this:

var SelectionGrid = new declare([OnDemandGrid, Selection, Keyboard]);

    var myGrid = new SelectionGrid({
                        store: myStore,
                        selectionMode: "single",
                        style: {
                            width: '99%',
                            height: '99%'
                        },
                        columns: columns
                    });

My problem is, the grid shows metadata for features I'm drawing in openlayers. I've written code in openlayers so that whenever I click on a feature on the map, it fires an event to scroll to that item in the grid and select it. The grid, however, doesn't pre-load the children for each parent, it only fetches the children when the parent row is expanded.

Currently I'm programmatically expanding every row and then reclosing them to force it to fetch, but it's terribly slow and ends up causing browser warnings about javascript taking too long to run, etc.

Is this a side effect of using OnDemandGrid? Is there anyway to just have all the data loaded so it's all available when the grid is rendered?

役に立ちましたか?

解決 2

I wasn't able to preload all my data, but I just discovered the glory of dojo/aspect. Now I find the parent item that needs expanded and I just build some code inside an aspect/after block that gets executed as soon as that row is finished expanding/loading:

aspect.after(grid, "expand", function (target, expand) {
                var row = grid.row(id);
                console.info("found row: ", row)
                grid.bodyNode.scrollTop = row.element.offsetTop;
                grid.clearSelection();
                grid.select(row);
                         }, 
                true); 
  grid.expand(item.id, true);

他のヒント

I had another issue and wanted to post another answer in case anybody has the same problem. When not using the Tree plugin and just using the OnDemandGrid, I couldn't programattically scroll to items in the grid that hadn't been loaded because the element for the row was null.

I found a property that tells the OnDemandGrid the minimum number of items to load from the store, and just set it to the length of my data, so it loads everything at once. I know that defeats the purpose/benefit of the OnDemandGrid, but it's the functionality I need. Here's the code:

var SelectionGrid = new declare([OnDemandGrid, Selection, Keyboard, DijitRegistry]);
var grid = new SelectionGrid({
                    store: store,
                    selectionMode: "single",
                    columns: columns,
                    minRowsPerPage: data.length,
                    farOffRemoval: 100000
                });

Here's the reference for minRowsPerPage and farOffRemoval:

http://dojofoundation.org/packages/dgrid/tutorials/grids_and_stores/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top