diff --git a/OnDemandList.js b/OnDemandList.js index 6f8206108..3377f005e 100644 --- a/OnDemandList.js +++ b/OnDemandList.js @@ -49,6 +49,10 @@ return declare([List], { // and tells it to refresh. this.query = query !== undefined ? query : this.query; this.queryOptions = queryOptions || this.queryOptions; + // stash sort details if the queryOptions included them + if(queryOptions && queryOptions.sort){ + this.sortOrder = queryOptions.sort; + } this.refresh(); }, diff --git a/test/test_OnDemand.html b/test/test_OnDemand.html index a418f5be9..6aab86d27 100644 --- a/test/test_OnDemand.html +++ b/test/test_OnDemand.html @@ -181,6 +181,36 @@ console.log("reset query to show all"); grid.setQuery({}); }); + + var sortDescending = true; + + on(document.getElementById("setQueryWithOptions"), "click", function(){ + // set sortOrder for the col1 field + sortDescending ^= 1; // toggle true/false + + // get an existing sortOrder + var sortByCol1 = dojo.filter( + grid.sortOrder || [], + function(sortBy){ + return sortBy.attribute == "col1"; + } + ).shift(); + if(sortByCol1){ + console.log("modifying existing sortOrder for col1: ", sortByCol1); + } else { + sortByCol1 = { attribute: "col1" }; + } + sortByCol1.descending = sortDescending; + grid.setQuery(grid.query, { sort: [sortByCol1] }); + }); + on(document.getElementById("sort"), "click", function(){ + console.log("sortOrder: ", grid.sortOrder); + + sortDescending ^= 1; // toggle true/false + grid.sort("col1", sortDescending); + }); + + on(document.getElementById("empty"), "click", function(){ console.log("set store to emptyStore"); grid.setStore(emptyStore, {}); @@ -264,6 +294,8 @@