PDA

View Full Version : Binding data view (grid etc) to results of store query



robmonie
18 Apr 2010, 11:51 PM
Hi All.

I'm hoping someone might be able to point me to the best approach for this. I'm sure it must be a common case. Typically a data bound component like a grid or dataview are bound to a store. If you want to filter what is displayed from the store in the component, you need to perform a filter on the store itself which would effect anything bound to the store and require that you perform some cleanup, say in the destroy method of the component, to clear the filter.

Is there a nice way you can create a kind of 'nested store' which is more like a temporary store based on the results of a query on the main store or better still, bind a store to the query results directly ? This would also need to be bound to changes to it's parent so that it could reflect those changes if need be in it's data.

I can think of ways of approaching this but I imagine it probably won't be straight forward so I wanted to check if anyone already does this sort of thing or whether there are better approaches.

Any ideas would be much appreciated!

-rob

robmonie
18 Apr 2010, 11:53 PM
Sorry, I just realised this is probably in the wrong forum. If a moderator could move it to the help forum that would be much appreciated!!

robmonie
19 Apr 2010, 2:06 AM
After a small amount of playing this seems to be relatively straight forward. I'm only at prototyping stage to see what sorts of things are possible so I won't be completing an implementation in the next couple of weeks but something like this seems feasible:

var filteredStore = new Ext.data.ArrayStore({
fields: App.store.parentStore.fields.items
});

filteredStore.add(App.store.parentStore.query("myfield", someValue).items);

This basically sets up a store with the fields of the one it's based on and loads the data from the query. From here I should be able to listen to the various important events from the parent store and update the filtered store based on some common logic. I can also do things like commit the changes from the filtered store back to the parent store if that becomes a requirement. It's starting to look a little like the nested store concept in sproutcore.

I think the devil will definitely be in the detail for this but it looks promising and is certainly logic that can be abstracted away into store extensions.

I'm certainly still interested in anyone's opinion or experience in this kind of approach.