Skip to content
Snippets Groups Projects
Commit 1c7cf6fb authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

ExtJS 4.2: Polish the grid reset.

parent 4d2db2a8
No related branches found
No related tags found
No related merge requests found
......@@ -67,8 +67,6 @@ Ext.define('App.grid.Grid', {
/**
* Reset the grid by removing filtering conditions
* and by loading fresh data when the store is buffered.
* TODO: duplicate with gridfilter.onReset. Improve it.
*
*/
reset: function () {
......
......@@ -13,8 +13,8 @@ Ext.define('App.grid.GridFilter', {
// this is used when running with a buffered store.
filterConditions: {},
// Private reference to the grid store
store: null,
// Private reference to the grid
grid: null,
// Predefined setting
//
......@@ -91,7 +91,7 @@ Ext.define('App.grid.GridFilter', {
}, this);
// remove private reference
this.store = null;
this.grid = null;
// base class
this.callParent(arguments);
......@@ -105,14 +105,14 @@ Ext.define('App.grid.GridFilter', {
"use strict";
var buttons = grid.query('button'),
reset;
buttonReset;
this.store = grid.getStore();
this.grid = grid;
// clicking the reset button of the grid reset the filter's fields.
if (buttons && buttons[0].menu) {
reset = buttons[0].menu.getComponent('buttonReset');
reset.on('click', this.reset, this);
buttonReset = buttons[0].menu.getComponent('buttonReset');
buttonReset.on('click', this.onReset, this);
}
},
......@@ -171,13 +171,14 @@ Ext.define('App.grid.GridFilter', {
"use strict";
var filter = this.store.filters.getByKey(field.name),
var store = this.grid.getStore(),
filter = store.filters.getByKey(field.name),
value = field.getValue();
// Clear an existing filter
if (filter && field.filterType === 'string' && value === "") {
this.store.removeFilter(filter);
store.removeFilter(filter);
return;
}
......@@ -191,13 +192,13 @@ Ext.define('App.grid.GridFilter', {
break;
}
filter.setValue(value);
this.store.filter();
store.filter();
return;
}
// create a new filter
filter = this.createLocalFilter(field);
this.store.addFilter(filter);
store.addFilter(filter);
},
/**
......@@ -211,7 +212,7 @@ Ext.define('App.grid.GridFilter', {
"use strict";
if (this.store.buffered) {
if (this.grid.getStore().buffered) {
this.remoteFiltering(field);
} else {
......@@ -226,19 +227,15 @@ Ext.define('App.grid.GridFilter', {
"use strict";
// reset field values and filter conditions
this.reset();
if (this.store.buffered) {
this.store.restoreWhere();
this.store.data.clear(true);
this.store.loadPage(1);
} else {
// reset the field values
this.items.each(function (item) {
if (item.isFormField) {
item.reset();
}
});
this.store.filter();
}
// reset the grid
this.grid.reset();
},
/**
......@@ -254,6 +251,7 @@ Ext.define('App.grid.GridFilter', {
var conditions = [],
i,
k,
store = this.grid.getStore(),
value,
where;
......@@ -279,9 +277,9 @@ Ext.define('App.grid.GridFilter', {
}
// build the complete where clause
if (this.store.initialWhere) {
for (i = 0; i < this.store.initialWhere.length; i += 1) {
conditions.push(this.store.initialWhere[i]);
if (store.initialWhere) {
for (i = 0; i < store.initialWhere.length; i += 1) {
conditions.push(store.initialWhere[i]);
}
}
......@@ -293,11 +291,11 @@ Ext.define('App.grid.GridFilter', {
// push new condition in the where clause of the store
if (conditions.length) {
this.store.extraParams.where = conditions;
store.extraParams.where = conditions;
// go back to the initial where setting when conditions are empty
} else {
this.store.restoreWhere();
store.restoreWhere();
}
// load the data
......@@ -306,30 +304,7 @@ Ext.define('App.grid.GridFilter', {
// Some records are not over written and correspond to
// the previous filtering. Clearing the buffer solve this issue.
// Copy from the method Ext.data.Store.reload
this.store.data.clear(true);
this.store.loadPage(1);
},
/**
* Reset the filter conditions
*/
reset: function () {
"use strict";
// reset the field values
this.items.each(function (item) {
if (item.isFormField) {
item.reset();
}
});
// reset filter conditions
if (this.store.buffered) {
this.filterConditions = {};
} else {
this.store.clearFilter();
}
store.data.clear(true);
store.loadPage(1);
}
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment