jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Search functionality for all the columns in grid › Reply To: Search functionality for all the columns in grid
Hi,
I faced a similar problem: I wanted to apply a global filtering condition to all columns of a grid. I have an input field where the user can input a substring and I want the table to show only those rows where anywhere on the row the substring occurs. In order to do this I have writte this function:
function setGlobalFilter (filtervalue) { var columns = cgTableObject.jqxGrid('columns'); var filtergroup, filter; // clear filters and exit if filter expression is empty cgTableObject.jqxGrid('clearfilters'); if (filtervalue == null || filtervalue == '') { return; } // the filtervalue must be aplied to all columns individually, // the column filters are combined using "OR" operator for ( var i = 0; i < columns.records.length; i++) { if (!columns.records[i].hidden && columns.records[i].filterable) { filtergroup = new $.jqx.filter(); filtergroup.operator = 'or'; filter = filtergroup.createfilter('stringfilter', filtervalue, 'contains'); filtergroup.addfilter(1, filter); cgTableObject.jqxGrid('addfilter', columns.records[i].datafield, filtergroup); } } cgTableObject.jqxGrid('applyfilters'); }
Maybe it helps you ?
(“cgTableObject” is the jQuery object reference for my table object)
Regards,
Stephan