PDA

View Full Version : Data grid of one store fires request to dynamically load a data grid of another store



dsutton
1 Jul 2014, 8:03 PM
I'm looking for a "How-To" Example of two data grids each with their own model & store. The catch is when the user clicks on a row in, let's say dataGrid1. An event is fired to load the store of dataGrid2 based on what the user selected in dataGrid1.

ie. dataGrid1 is a list of customers which is an autoloaded store. Then there is a dataGrid2 which is a list of customer orders. So our user clicks on a customer name in dataGrid1 and that fires off an event to the store of dataGrid2 (which is empty at the moment). That event tells the dataGrid2 store to only load the orders for that customer. When a user clicks on another customer in dataGrid1 the dataGrid2 store clears and reloads with that new customer orders.

I know I can use other things to make this behavior happen (ei. the Cars example in the getting started), but I'd like to have it all contained in data grids and stores. Filtering the second store doesn't buy me what I really want and that's cacheing only the data I really want to use and not the whole database table.
I'm using Architect so I'd like to keep things MVC.

Thanks!

evant
1 Jul 2014, 8:06 PM
FYI functionality that allows this to happen more easily was added in 5.0.0, see:

http://dev.sencha.com/ext/5.0.0/examples/kitchensink/#binding-associations

For 4, you'll need to hook up the listeners manually.

1) The child store should have a remote filter
2) Listen for the selectionchange event
3) Change the filter on the child store as appropriate
4) Reload the store

dsutton
2 Jul 2014, 9:46 AM
Thanks Evan,

I like the version 5 example. I'll take a look at the code and see what's going on behind the curtain.

As for the version 4 seems like we're still relying on EXT to do the heavy lifting. We're still loading the whole db table into the child store and then just filtering as needed. Like to fire off a REST to the php backend and have php return data to the child store.

In my case bandwidth is not an issue. So a couple thousand requests to php is just fine. Still it's nice to have your option to fall back on.

Again thanks to pointing out the version 5 example.