Check documentation for the latest version of dhtmlxSuite Filtering DHTMLX Docs


There are 4 ways to implement a server-side filtering:

Be careful, the server-side filtering of dhtmlxTreeGrid doesn't maintain open states.

The filter() method

It's probably the easiest way to implement the server-side filtering. All you need to do is to call the filter() method.

$grid->filter("item_nm", "member");
//or   $grid->filter("item_nm='member'");

URL manipulation

APPLICABLE TO:Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form, DataStore components

You can control what data is loaded into the component by specifying additional parameters in URL.

Check the article Extending functionality for full URL parameters' description.

  • filtering by one field

With such a url data will be taken with an additional rule.

WHERE field_for_column_1 LIKE %mask%
  • filtering by multiple fields

For all the components, except for dhtmlxGrid you should provide the exact field's name instead of the column's index.

Remember that such filtering is non-secure and if you need to hide some data, make sure to define the appropriate limitation on the server side, not as a part of URL.

In-header filter types

APPLICABLE TO: Grid, TreeGrid, Combo

To enable the server-side filtering you can use one of the following in-header filter types while configuring dhtmlxGrid/dhtmlxTreeGrid on the client side:

  • #connector_text_filter - a text filter. Retrieves values which contain a mask defined through a text field
  • #connector_select_filter - a select filter. Retrieves values which contain a mask defined through a dropdown list of possible values
mygrid.setHeader("Column A, Column B");

Text filter

The use of the text filter doesn't require any additional configuration code. Grid/TreeGrid will automatically send data about a newly entered text and filter server-side data using the %mask% pattern.

If you need to change the filtering pattern or implement a more advanced logic - the beforeFilter event should be used.

  • default filtering logic
function custom_filter($filter_by){
    //WHERE some_field LIKE 'value'
    if (!sizeof($filter_by->rules)) 
  • redefined filtering logic
function custom_filter($filter_by){
    if (!sizeof($filter_by->rules)) 
    //change WHERE some_field LIKE '%value%' to the WHERE some_field > 'value'
    $index = $filter_by->index("some_field");
    if ($index!==false)  //a client-side input for the filter

Through rules[$index] you can refer to:

  • the name of a field (rules[$index]["name"]="age")
  • the value of a field (rules[$index]["value"]="30")
  • the type of an operation (rules[$index]["operation"]=">")

Select filter

By default, Grid/Treegrid will use DISTINCT select against the related field, and fetch all possible options.

If you need to define a custom list of options you can use one of 2 ways:

  • a hardcoded list
  • a list created on the base of a different table
$filter1 = new OptionsConnector($res);

You can use both the render_table and render_sql methods for OptionsConnector object, the same as for any normal connector.

Remember that the name of the field used in the select filter needs having the (value) alias.

Custom filters (using the beforeRender event)


By using the beforeRender event it's possible to define filtering rules as PHP code (doesn't work for dyn. modes).

function custom_filter($data){
    if ($data->get_value("some")<0)
        $data->skip(); //not include into output
  • "some" - in this example is a name of a data property, i.e. the column listed in 'SELECT' part of sql statement: "SELECT event.userID, ...."

You can read about the methods that are used by different components in the DataItem Object API.

Back to top