Skip to content

Instantly share code, notes, and snippets.

@lukeasrodgers
Created April 24, 2013 20:47
Show Gist options
  • Save lukeasrodgers/5455440 to your computer and use it in GitHub Desktop.
Save lukeasrodgers/5455440 to your computer and use it in GitHub Desktop.
Extensions to Ext.grid.GridPanel to make it easier to do programmatically hook into grid filtering.
Ext.grid.GridPanel.prototype.getFeatures = function() {
return this.view.featuresMC;
};
Ext.grid.GridPanel.prototype.getFilters = function() {
var features = this.getFeatures();
if (features && features.items) {
for (var i = 0; i < features.items.length; i++) {
if (features.items[i].ftype === 'filters') {
return features.items[i];
}
}
}
};
Ext.grid.GridPanel.prototype.createFilters = function() {
var filters = this.getFilters();
if (filters) {
filters.createFilters();
}
};
Ext.grid.GridPanel.prototype.filter = function(field, value) {
var filters = this.getFilters();
if (!filters || !filters.filters) {
throw new Error ('Could not filter: no filters defined');
}
var filter_items = filters.filters.items;
var filter;
for (var i = 0; i < filter_items.length; i++) {
if (filter_items[i].dataIndex === field) {
filter = filter_items[i];
}
}
if (!filter) {
throw new Error ("No matching filter");
}
filter.setValue(value);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment