JohnB
JohnB

Reputation: 345

Sorting a Column by Default (on load) Using Dojo Dgrid

When loading a dgrid from a dojo store, is there a way to specify a column to be sorted by default.

Say I have 2 columns, Name and Email, I want the name column sorted by default when the grid is first loaded. What I want is the equivalent of the user clicking on the 'Name' header (complete with the sort arrow indicating the sort direction).

Thanks, John

Upvotes: 5

Views: 7987

Answers (2)

user2182349
user2182349

Reputation: 9782

dgrid 1.1.0 - set initial/default sort order

    var TrackableRest = declare([Rest, SimpleQuery, Trackable]);
    var store = new TrackableRest({target: apiUrl, useRangeHeaders: true, idProperty: 'id'});
    var grid = new (declare([OnDemandGrid, Selection, Editor]))({
        collection: store,
        sort: [{"property":"name", "descending": false}],
        className: "dgrid-autoheight",
        columns: {
            id: {
                label: core.id
            },
            category_text: {
                label: asset.category
            },
            name: {
                label: asset.model,
            },

Upvotes: 0

Philippe
Philippe

Reputation: 6828

You can do something like this :

var mygrid = new OnDemandGrid({
    store : someStore,
    queryOptions: {
        sort: [{ attribute: "name" }]
    }
    // rest of your grid properties
}, "someNode");

Upvotes: 9

Related Questions