| DHTMLX Documentation

# Data filtering

Starting from dhtmlxgrid 1.5 the grid supports filtering API, which works in the normal, paging and smart rendering modes (filtering in smart rendering mode is the fastest one, that's why it is recommended to be used with relatively big datasets).

### Built-in filters

The simplest way to use filters is to create a filter in the header by using shortcuts (You can study the related topic).
Built-in filters are grouped by AND logic in such a way that if you create filters for 3 columns, the data will be shown only if it is accepted by all 3 sorting criteria.

### Filtering API

The second way to create some filtering is to use API calls. The grid provides a simple way to filter the grid by any column:

> grid.filterBy(column,value);

- column - zero based column index;
- value - value by which the column will be filtered.

You can use simple values for filtering:

> grid.filterBy(1,"alf");

Or complex javascript rules:

> grid.fitlerBy(1,function(data){
> return data.toString().indexOf("alf")!=-1; // true - show the related row , false - hide the related row
> });

Every next call of filterBy will reset the grid to its initial state and filter it from the start. There is the possibility to use the following additional parameters here:

> grid.filterBy(1,"alf");
> grid.filterBy(2,"Omega"); // the first rule will be ignored
> grid.filterBy(1,"alf");
> grid.filterBy(2,"Omega",true); // the grid will be filtered by both rules

There is no way to use several filters with OR logic between them.

### Simplified filter creation

To simplify filter creation there is a method in the grid that will convert any external INPUT or SELECT element into the filter:

> <input id='some_el' type='text'>
> ....
> grid.makeFilter("some_el",index); // will create a text filter linked to the specified column in the grid

> <select id='some_el' type='text'></select> // the options of select will be added automatically
> ....
> grid.makeFilter("some_el",index); // will create a select filter linked to the specified column in the grid

### Additonal API

The following API methods are rarely used, but they may be also useful in some situation:

> grid.refreshFilters(); // refresh lists of values in all the filters created by shortcuts or by makeFilter calls
> grid.collectValues(index); // return alphabetically sorted list of unique values in a column

© DHTMLX, 2008