MikeTheReader
MikeTheReader

Reputation: 4190

Dojo DataGrid with Sorting - Can I get at the new order?

I am working with a dojox.grid.DataGrid on my page, and I have it working the way I want to, and it sorts everything very nicely. However, after the grid is sorted, I would like some way to get at the data in the sorted order.

I'm using an ItemFileReadStore as the data store, and that remains in the original order (which is good) - so I can't use that.

If I try to iterate through the items in the Grid's store, they come up in the right order, but not all of them are loaded, so once I get past the 25 that I show originally, the values come up as null.

Is there any simple way to either (a) get the order that the Grid is using or (b) iterate through the items in the correct order?

Thanks.

Upvotes: 0

Views: 1274

Answers (1)

Tom Gruner
Tom Gruner

Reputation: 9635

It seems that you can call grid.getSortProps() and pass that as the sort paramater to fetch directly.

Here is a fiddle:

http://jsfiddle.net/BMQAa/2/

and a bit of code:

var getPlanetList = function getPlanetList() {
    var sortProps = grid.getSortProps();
    store.fetch({sort: sortProps, 
                 onComplete : function(items) {
        var list = [];
        for (var i in items) {
           var planet = store.getValue(items[i], 'planet');
           list.push(planet);
        }

        var html = '<p>' + list.join(', ') + '</p>';

        dojo.place(html, 'info', 'only');
    }})
}

Upvotes: 1

Related Questions