Filtering for detail records in dojo
I have a page with a dijit.Tree, and a dojox.grid.EnhancedGrid both hooked up t开发者_StackOverflowo some hierarchical data in an ItemFileWriteStore. When the user clicks on an item in the tree, I want to be able to show only the immediate children of that item in the grid, along with their attributes. This is a rather common pattern in database applications, but I can't find any examples of this, or perhaps I'm looking in the wrong place.
Looking at the grid docs, I see a setQuery method on the DataGrid. However, looking at the query syntax for ItemFileReadStore, I don't see anything that would let me specify to fetch only the children of a given item. Is there something I'm missing, is there another way to do this?
Using dojo 1.5.
(Edited for clarity)
Well, since no one answered, I came up with my own solution. I figured that this should be something that should have been built in to the DataStore framework, so I found an appropriate method in ItemFileReadStore to hook into, and extended it to add some query options to allow detail queries.
The following code adds two available QueryOptions arguments (parentItem, parentAttribute) which specify a parent item and a parent attribute for detail drill-down queries. They aren't compatible with the 'deep' option as the expected result of a combination of those two isn't clear.
dojo.extend(dojo.data.ItemFileReadStore, {
_getItemsArray: function(/*object?*/queryOptions) {
if (queryOptions) {
if (queryOptions.deep && queryOptions.parentItem) {
throw "Invalid query: a drill-down search can not be 'deep'"
}
if (queryOptions.deep) {
return this._arrayOfAllItems;
}
if (queryOptions.parentItem) {
if (!queryOptions.parentAttribute) {
throw "Invalid query: an attribute is required for drill-down searches.";
}
return this.getValues(queryOptions.parentItem,queryOptions.parentAttribute);
}
}
return this._arrayOfTopLevelItems;
}
});
The above code is available for anyone to use.
精彩评论