PDA

View Full Version : Shared Stores and common data



johnholden
17 Nov 2010, 7:32 PM
Hello,

I am building an application that references a table (called "companies") which is used by a number of different logical components. For instance, "shipper" companies are in this table, as are "clients" and "supplier". In the table, a single "type" column differentiates between record types. Nothing special.

I would rather only load the data in one request, but I'm not sure how *best* to code this. There are several forms and grids in the application that would access this store(s) all the time. For instance, if I just have a "companies" store, but on a form I have each of "shipper" and "supplier" comboboxes, how can I filter to show the right options in one combobox without canceling the filter on the other?

Should I clone the store and register one for each logical record type? Or is there a better way?

Thanks in advance,

John

johnholden
22 Nov 2010, 12:51 PM
Does anyone have a suggestion? I still haven't found a good solution...

moegal
22 Nov 2010, 2:21 PM
can't you just use a filter on the store for each combobox? store.filter...

johnholden
22 Nov 2010, 2:37 PM
Well that's the problem... filtering the store affects the data displayed by all components that use the store.

Condor
23 Nov 2010, 5:27 AM
Correct. You'll have to create a second store that only contains a copy of the relevant records from the first store.

mschwartz
23 Nov 2010, 6:37 AM
Load the data into one store, call it store1. To load them into store2 as well:

store2.add(store1.getRange());

Condor
23 Nov 2010, 6:44 AM
No, a record can only belong to a single store.

You either have to load the second store with the same data:

store2.loadData(store1.reader.jsonData);
or add copies of the records from the first store to the second store.

mschwartz
23 Nov 2010, 6:57 AM
No, a record can only belong to a single store.

You either have to load the second store with the same data:

store2.loadData(store1.reader.jsonData);
or add copies of the records from the first store to the second store.



var copies = [];
for (var i=0, records=store1.getRange(), len=records.length; i<len; i++) {
copies.push(records[i].copy());
}
store2.add(copies);