From e345b81bffb0077825f3859f9f396fb6d5067895 Mon Sep 17 00:00:00 2001 From: "Kenneth G. Franqueiro" Date: Fri, 27 Sep 2013 21:03:50 -0400 Subject: [PATCH] tree: include originalQuery in getChildren options for filtering This gives getChildren access to the original query via options.originalQuery, permitting it to re-apply the root query against child levels. --- test/data/base.js | 45 ++++++++++++++++++++++----------------------- test/tree.html | 33 +++++++++++++++++++++------------ tree.js | 6 ++++-- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/test/data/base.js b/test/data/base.js index 9b2944a11..35d4c8d83 100644 --- a/test/data/base.js +++ b/test/data/base.js @@ -5,9 +5,10 @@ define([ "dojo/_base/Deferred", "dojo/store/Memory", "dojo/store/Observable", - "dojo/store/util/QueryResults" + "dojo/store/util/QueryResults", + "./DeferredWrapper" ], -function(lang, arrayUtil, Deferred, Memory, Observable, QueryResults){ +function(lang, arrayUtil, Deferred, Memory, Observable, QueryResults, DeferredWrapper){ // some sample data // global var "data" data = { @@ -208,37 +209,35 @@ function(lang, arrayUtil, Deferred, Memory, Observable, QueryResults){ { id: 'BuenosAires', name:'Buenos Aires', type:'city', parent: 'AR' } ]; - // global var testCountryStore - testCountryStore = Observable(new Memory({ - data: testCountryData, - getChildren: function(parent, options){ - return this.query({parent: parent.id}, options); - }, - mayHaveChildren: function(parent){ - return parent.type != "city"; - }, - query: function(query, options){ - var def = new Deferred(); - var immediateResults = this.queryEngine(query, options)(this.data); - setTimeout(function(){ - def.resolve(immediateResults); - }, 200); - var results = QueryResults(def.promise); - return results; - } - })); - // global var testSyncCountryStore testSyncCountryStore = Observable(new Memory({ data: testCountryData, getChildren: function(parent, options){ - return this.query({parent: parent.id}, options); + // Support persisting the original query via options.originalQuery + // so that child levels will filter the same way as the root level + return this.query( + lang.mixin({}, options && options.originalQuery || null, + { parent: parent.id }), + options); }, mayHaveChildren: function(parent){ return parent.type != "city"; + }, + query: function (query, options){ + query = query || {}; + options = options || {}; + + if (!query.parent && !options.deep) { + // Default to a single-level query for root items (no parent) + query.parent = undefined; + } + return this.queryEngine(query, options)(this.data); } })); + // global var testCountryStore + testCountryStore = new DeferredWrapper(testSyncCountryStore); + var testTopHeavyData = arrayUtil.map(testStateStore.data, function (state) { return { abbreviation: state.abbreviation, diff --git a/test/tree.html b/test/tree.html index 8e1c3131f..37c85cc1f 100644 --- a/test/tree.html +++ b/test/tree.html @@ -49,7 +49,6 @@ var treeGrid = window.treeGrid = new StandardGrid({ store: testCountryStore, - query: {type: "continent"}, columns: [ tree({label: "Name", field:"name", sortable: false}), editor({label: "Visited", field: "bool", sortable: false}, "checkbox"), @@ -59,6 +58,13 @@ ] }, "treeGrid"); + on(byId("filter"), "click", function(){ + treeGrid.set("query", { name: /a$/ }); + }); + on(byId("clearFilter"), "click", function(){ + treeGrid.set("query", {}); + }); + on(byId("save"), "click", function(){ treeGrid.save(); }); @@ -112,7 +118,6 @@ window.treeSelector = new StandardGrid({ store: testCountryStore, - query: {type: "continent"}, selectionMode: "none", allowSelectAll: true, columns: getTreeSelectorColumns() @@ -135,7 +140,6 @@ window.treeSubRows = new StandardGrid({ store: testCountryStore, - query: {type: "continent"}, subRows: [[ tree({label:"Name", field:"name", sortable: false}), {label:"Type", field:"type", sortable: false} @@ -147,7 +151,6 @@ window.treeColumnSets = new (declare([Grid, Keyboard, Selection, ColumnSet]))({ store: testCountryStore, - query: {type: "continent"}, columnSets: [[ [ tree({label:"Name", field:"name", sortable: false}) ], [ {label:"Type", field:"type", sortable: false} ] @@ -166,14 +169,20 @@

Lazy-loading tree grid, with store functionality

- - - - - - - - +
+ + +
+
+ + + + + + + + +

Tree grid with formatter on tree column, and a checkbox selector to test select-all on children

diff --git a/tree.js b/tree.js index 7e6bec7b9..16c12edab 100644 --- a/tree.js +++ b/tree.js @@ -195,7 +195,9 @@ function tree(column){ container, containerStyle, scrollHeight, - options; + options = { + originalQuery: this.query + }; if(!preloadNode){ // if the children have not been created, create a container, a preload node and do the @@ -209,7 +211,7 @@ function tree(column){ // If allowDuplicates is specified, include parentId in options // in order to facilitate unique IDs for each occurrence of the // same item under multiple different parents. - options = { parentId: row.id }; + options.parentId = row.id; } // Include level information on query for renderQuery case if("level" in target){