View Full Version : filter empty cells using gridfilter

16 Apr 2010, 7:33 AM
Im pretty new to ext js... been using it for about 2 weeks and needed it for its great grid capabilities.

I needed to have a "hide empty" option in the grid filter... and i modified the files GridFilters.js and StringFilters.js in order to do it...
I dont think the method i did it in is the most elegant or best and would love some comments on how to improve it.

In GridFilters.js i modified the onMenu function and added a few handler functions:

* @private
* Handler called by the grid's hmenu beforeshow event
onMenu : function (filterMenu) {
var filter = this.getMenuFilter();

if (filter) {
TODO: lazy rendering
if (!filter.menu) {
filter.menu = filter.createMenu();
this.menu.menu = filter.menu;
if (!filter.menu.get('hide_empty'))
this.menu.setChecked(filter.active, false);
// disable the menu if filter.disabled explicitly set to true
this.menu.setDisabled(filter.disabled === true);

this.menu.setVisible(filter !== undefined);
this.sep.setVisible(filter !== undefined);

addEmptyFilter : function(filter) {
var item = new Ext.menu.CheckItem({
text: 'Hide Empty?',
itemId: 'hide_empty',
checked: false,
hideOnClick: false});
item.on('checkchange', this.emptyToggle,this);

emptyToggle : function(obj,checked){
var filter = this.getMenuFilter();
//var dataIndex = {index: filter.dataIndex, action: 'hide_empty'};
var dataIndex = filter.dataIndex + '::hide_empty';
if (checked)
if (this.filters.get(dataIndex))
this.addFilter({type:'string',dataIndex: dataIndex,active:true});
And then in StringFilter.js I changed the ValidateRecord function to this:

validateRecord : function (record) {
var dataIndex = this.dataIndex.split('::');
var val = record.get(dataIndex[0]);
if (dataIndex[1] == 'hide_empty')
return Ext.util.Format.stripTags(val) != '';

var val = record.get(this.dataIndex);
if(typeof val != 'string') {
return (this.getValue().length === 0);

return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
},seems like it works pretty well although it does seem to confuse the headers as to when a filterlist is active, or when a filter is active...
any advice on how to improve that would be great.