Skip to content

Commit

Permalink
Merge pull request dojo#31 from sfoster/ondemand-queryoptions
Browse files Browse the repository at this point in the history
Ensure sort details included in queryOptions are retained in list.sortOrder
  • Loading branch information
SitePenKenFranqueiro committed Oct 20, 2011
2 parents 00c7974 + 591e8c0 commit 52ed18b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions OnDemandList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},

Expand Down
32 changes: 32 additions & 0 deletions test/test_OnDemand.html
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
Expand Down Expand Up @@ -264,6 +294,8 @@ <h2>Simple test to show setting a new store and query to dgrid</h2>
<button id="restore">Set Original Store</button>
<button id="colorQuery">Set color store and query</button>
<button id="resetQuery">Reset query</button>
<button id="setQueryWithOptions">Set query with queryOptions</button>
<button id="sort">sort</button>
<button id="empty">Set to empty store</button>
<button id="error">Set to error store</button>
<button id="error2">Set to error store (def)</button>
Expand Down

0 comments on commit 52ed18b

Please sign in to comment.