PDA

View Full Version : [FIXED] Ext.ux.grid.FiltersFeature cannot restore state



jdemoor
25 Jun 2011, 7:34 AM
Ext version tested:


Ext 4.0.2a



Browser versions tested against:


FF5
Chrome



Description:


The grid filters fail to restore their state when the grid has stateful = true.



Steps to reproduce the problem:


Have a working grid with some filters such as in the official example
Make the grid stateful



The result that was expected:


Filters that work and have persistent state



The result that occurs instead:


Filters disappear when specified on the column definition, fail to restore their state otherwise



HELPFUL INFORMATION




Debugging already done:


FiltersFeature.attachEvents() set an event listener on the grid's beforestaterestore event, but is itself called after the grid is rendered. At that time, the grid's state is already restored. My patch below fixes the issue in my case (it's not perfect in the way it gets to the grid's saved state).
The documentation states (correctly) that one may specify a filter within the grid column definition, rather than the FiltersFeature definition. However, when doing so the configuration is erased as soon as the grid restores its columns.



Possible fix:

--- FiltersFeature.orig.js 2011-06-14 23:19:48.000000000 +0200
+++ FiltersFeature.js 2011-06-25 17:08:50.423354600 +0200
@@ -224,6 +224,12 @@
// Add event and filters shortcut on grid panel
grid.filters = me;
grid.addEvents('filterupdate');
+
+ me.createFilters();
+ if (grid.stateful) {
+ me.applyState(grid, Ext.state.Manager.get(grid.stateId));
+ }
+
},

createFiltersCollection: function () {
@@ -295,7 +301,7 @@
*/
onMenuCreate: function(headerCt, menu) {
var me = this;
- me.createFilters();
+ // me.createFilters();
menu.on('beforeshow', me.onMenuBeforeShow, me);
},

yozik04
27 Jul 2011, 5:59 AM
I have found the same problem. What I did? I have overridden initState function for grid instance. I basically deferred original function so state will apply after all features will be already created. Then I initialize FiltersFeature manually by calling createFilters on it.


var filtersCfg = {
id: 'filters',
ftype: 'filters',
local: true, // defaults to false (remote filtering)
filters: [
{
type: 'string',
dataIndex: 'operator'
}
]
};

var grid = Ext.create('Ext.grid.Panel',{
xtype: 'grid',
features: [filtersCfg],
...
initState: function() {
Ext.Function.defer(Ext.grid.Panel.prototype.initState, 1, this, arguments); //defer state initialization so features will also get the state
}
});

grid.getView().getFeature('filters').createFilters();


But I think this is more like a hack :)

extjs@kingsquare.nl
12 Jun 2012, 4:03 AM
This issue still exists in Extjs 4.1.0

And i can confirm that the patch supplied by jdemoor actually fixes it, thanx!

Please fix this issue in the upcoming release (with this, or a better patch)

burnnat
25 Jun 2012, 7:01 AM
+1

Would be nice to see this long-standing bug finally fixed...

extjs@kingsquare.nl
8 Nov 2012, 2:54 AM
This issue still exists in Ext 4.1.3 :(

mhev
30 Nov 2012, 8:21 AM
TypeError: el is null
ext-all-debug-3.js (Line 3019)

This bug occurs after applying suggested patch.

Possible fix:

--- FiltersFeature.orig.js 2011-06-14 23:19:48.000000000 +0200
+++ FiltersFeature.js 2011-06-25 17:08:50.423354600 +0200
@@ -224,6 +224,12 @@
// Add event and filters shortcut on grid panel
grid.filters = me;
grid.addEvents('filterupdate');
+
+ // just add one listener here
+ headerCt.on('columnmove', me.createFilters, me);
+
+ me.createFilters();
+ if (grid.stateful) {
+ me.applyState(grid, Ext.state.Manager.get(grid.stateId));
+ }
+
},

createFiltersCollection: function () {
@@ -295,7 +301,7 @@
*/
onMenuCreate: function(headerCt, menu) {
var me = this;
- me.createFilters();
+ // me.createFilters();
menu.on('beforeshow', me.onMenuBeforeShow, me);
},

stegg
19 Dec 2012, 8:36 AM
When will this issue finally be fixed?
I just migrated my application from ExtJS 3 to 4.1.3 when I discovered this issue.
It is kind of sad when a 1.5 year old issue is still not resolved by Sencha.

kleins
26 May 2013, 10:08 PM
Bug still exists. This is very simple to fix, but annoying to work around.

burnnat
20 Jun 2013, 9:33 AM
Does anyone have an override for this working in ExtJS 4.2? I'm trying to use the workaround from the original report, but it's not having any effect for me in 4.2...

geek0r
24 Jul 2013, 4:41 AM
+1 to get this finally fixed! Astonishing how long this is an open issue!

Oliver Timm
21 Aug 2013, 3:17 AM
When will this be fixed. Need for several projects and workaround doesn't work in 4.2.1 :(

wared
27 Aug 2013, 2:39 AM
Bug still exists. This is very simple to fix, but annoying to work around.

Hi Kleins! Could you tell us how you did it? Thanks!

ndrake
30 Aug 2013, 5:11 PM
Just another voice wondering when this will be fixed and if anyone has a workaround that works in 4.2.1.

Animal
9 Sep 2013, 10:46 AM
It looks like it's just a timing problem. The FiltersFeature attempts to hook the grid's state restoration to restore its own state. Just that the individual Filter objects are not available at that time as they are created lazily.

So I have a proposed fix which makes the standard example page (examples/grid-filtering/grid-filter-local.html) work with statefulness turned on:



Ext.override(Ext.ux.grid.FiltersFeature, {
init: function(grid) {
var me = this,
view = me.view,
headerCt = view.headerCt;

me.bindStore(view.getStore(), true);

// Listen for header menu being created
headerCt.on('menucreate', me.onMenuCreate, me);

view.on('refresh', me.onRefresh, me);
grid.on({
scope: me,
beforestaterestore: me.applyState,
beforestatesave: me.saveState,
beforedestroy: me.destroy
});

// Add event and filters shortcut on grid panel
grid.filters = me;
grid.addEvents('filterupdate');
me.createFilters();
},

onMenuCreate: function(headerCt, menu) {
var me = this;
// This code is gone: me.createFilters();
menu.on('beforeshow', me.onMenuBeforeShow, me);
},

getGridPanel: function() {
// This reference is injected in TableView.initFeatures
return this.grid;
}
});

ndrake
9 Sep 2013, 11:07 AM
Thanks, Animal! Your fix is working for me in 4.2.1.

Oliver Timm
10 Sep 2013, 6:27 AM
Thanks Animal, works fine! Did/will you commit it to head and will it be part of the next patch/minor release?

dongryphon
10 Sep 2013, 5:48 PM
This fix is merged for 4.2.2 -- coming soon. :)

alex.ban
3 Oct 2013, 7:47 AM
This fix causes a new issue on version 4.2.1.883.
Applying a filter on a column and moving that column will cause its filter's options to not render.

I'm getting 'Uncaught TypeError: Cannot read property 'addCls' of null' - ext-all-debug-w-comments line 44393.

Can anyone else confirm this?

riyash
23 Dec 2013, 4:09 AM
Me too facing the same issue