PDA

View Full Version : How to handle a combobox that use the same store as a grid, which is filtering it?



Fire-Dragon-DoL
14 Oct 2012, 3:35 PM
I have a "stupid" problem, in my application I have (let's suppose) the store Comments and the store Authors. Comment has one author.

Now, I have a grid to edit comments and one to edit authors, however when I'm editing the comments one and I use a combobox to choose the author, which use the same store as the authors grid, which may be filtered by the user for (example) name, the combobox appears filtered too.

What are available solutions to keep the filtering on the authors grid while having "all" the authors (paged possibly) on the combobox?

vietits
14 Oct 2012, 5:02 PM
My solution is to create a separate store for the combobox.

Fire-Dragon-DoL
14 Oct 2012, 5:35 PM
My solution is to create a separate store for the combobox.

Actually I'm doing it too (I created a combobox that autogenerate a store). I hoped for a better solution anyway. Like storing filters and restoring them after

scottmartin
16 Oct 2012, 5:43 AM
Store is the best option ... and they are cheap .. just a few lines of code.

Fire-Dragon-DoL
16 Oct 2012, 6:51 AM
Store is the best option ... and they are cheap .. just a few lines of code.

Yea but what "bothered" me is the fact that I have to reload it through the network, so I'm wasting bandwidth, it's not a matter of coding actually.

skirtle
16 Oct 2012, 9:43 AM
You shouldn't need to reload the store from the server. If you're using ExtJS 4.1 then records can be shared between multiple stores. You can have a master store that loads from the server and then create copies wherever you need those records. While the records will be shared the filtering and sorting will be specific to each store.

Fire-Dragon-DoL
16 Oct 2012, 10:08 AM
You shouldn't need to reload the store from the server. If you're using ExtJS 4.1 then records can be shared between multiple stores. You can have a master store that loads from the server and then create copies wherever you need those records. While the records will be shared the filtering and sorting will be specific to each store.

That's REALLY interesting, two questions however:

How does the master store behaves with filtering? I mean, if a child store request to filter, does this store require that this filter is implemented locally and not remotely?
Last thing, how does this structure handle paging? Do I need to load ALL records? I'm afraid of loading tons of records. Imagine what happens if I have 30 000 records in a table... Expecially I used remote filtering actually to reduce records, and I can't imagine how child stores handles this (no problem in changing, just I want to understand how to face "tons of records" problem)

skirtle
16 Oct 2012, 10:31 AM
Don't dwell too much on the term 'master store'. I really just mean a source store that already contains the records you want.

All I'm really saying is that you can take the records in one store and add them to another store to avoid having to make an extra request to the server. If you also want to copy the filtering or paging state from one store to the other then obviously you can but it'll make things much more complicated. Once the second store is created there isn't an on-going link back to the original store unless you choose to create one.

Fire-Dragon-DoL
16 Oct 2012, 11:07 AM
Don't dwell too much on the term 'master store'. I really just mean a source store that already contains the records you want.

All I'm really saying is that you can take the records in one store and add them to another store to avoid having to make an extra request to the server. If you also want to copy the filtering or paging state from one store to the other then obviously you can but it'll make things much more complicated. Once the second store is created there isn't an on-going link back to the original store unless you choose to create one.

Maybe the fact that I can just copy data is even better: I'll check if filters are applied (if that's the case I basically reload everything in the "child" store directly from the server), if not, I copy all available data. Thanks.

Can you post (if it's really short) how to make this data copy from store to store?

skirtle
16 Oct 2012, 11:58 AM
newStore.add(oldStore.getRange());

Fire-Dragon-DoL
16 Oct 2012, 11:59 AM
Thanks a lot, I'll work on it