Hybrid View
-
29 Jun 2012 5:54 AM #1
(4.1) Should store.add respect filters?
(4.1) Should store.add respect filters?
Hi,
I have a memory store which an asynchronous ajax call occasionally adds records to. This store can be configured at run-time with filters and sorts and is backing a grid.
The problem is that if I add a record (store.add(..)) which doesn't match the current filter it is still displayed on the grid. Calling store.filter() hides it, but it also unfortunately resets any groupings (expanded/collapsed) and scroll co-ordinates.
It if helps, imagine I am building a grid which display server side log messages. It is updated every N seconds by an Ajax call which manually updates the store. The GUI allows you to filter messages though - maybe you only want to see SEVERE messages for example.
So my question is, how can I add a record to a (memory) store which is backed by a grid with filters so the grid only shows that item if it matches the current filter without losing the scroll and group state?
Thanks!
-
29 Jun 2012 6:23 AM #2
Trawling through the forums again I found: http://www.sencha.com/forum/showthre...-EXTJS-4/page3 which links to http://docs.sencha.com/ext-js/4-1/#%...crollOnRefresh, which seems to work a treat!
Now to find a corresponding "preserveGroupsOnRefresh"...
-
29 Jun 2012 1:28 PM #3
More context - this is only a problem if the group plugin is configured "startCollapsed:true" (which isn't the default)
-
30 Jun 2012 10:46 AM #4
Is it solved or you need some assistance?
Jozef Sakalos, aka Saki
A lot of valuable info at:
Saki's Extensions and Plugins
Saki's Extensions and Plugins Docs
Saki's Examples, Latest: Grid in Card Layout
Saki's Blog, Featured: Writing a Big Application in Ext, Latest: Grid MultiSearch Plugin Video
-
1 Jul 2012 7:06 AM #5
My query still stands - when calling store.add() on a grid's store, should a record appear on the grid if it doesn't match the filter? My experiments indicate that the record does still appear until store.filter is called.
To be clear, I have a memory backed store, and a grid with a simple filter of "departmentId"=5. If I add a record {name:'hi-ho',departmentId:10} then it will appear on that grid until I call store.filter(). Is that expected behaviour?
-
1 Jul 2012 7:34 AM #6
The story continues
.
I have found that if I have a record which *does* match a filter and then I update it so that it no longer matches the filter it is still (incorrectly) displayed in the grid, even after a store.filter(). Adding a new record does the right thing, so instead of updating it I remove and re-add it:
Removing and re-adding is unfortunate as it loses row-selection and isn't "the right thing to do", but I can live with it.Code:var existingRecord = store.getById(newRecord.id); if (existingRecord != null) { /* Editing the record updates it and the subsequent store.filter() removes it from view if necessary, however, *new* records which should be in the filter aren't added. To work around this, delete the existing record and re-add it. */ // existingRecord.beginEdit(); // var fields = existingRecord.fields; // for (var i = 0; i < fields.length; i++) { // var key = fields.get(i).name; // var newValue = newRecord.get(key); // existingRecord.set(key, newValue); // } // existingRecord.endEdit(); store.remove(existingRecord); records.push(newRecord); } else { records.push(newRecord); } .. .. store.add(records); store.filter();
Should I create a small demo and post as a bug report? I am hesitant as almost certainly the bug is in my code or understanding ....
You found a bug! We've classified it as
EXTJSIV-6715
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote