There are 3 ways to implement server-side filtration:
APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form, DataStore, DHTMLX Touch components
You can control which data was loaded into component by specifying additional parameters in URL.
grid.load("some.php?connector=true&dhx_filter[1]=mask");
With such url - data will be taken with additional rule.
WHERE field_for_column_1 LIKE %mask%
grid.load("some.php?connector=true&dhx_filter[1]=mask&dhx_filter[3]=another");
For components other than Grid you should provide exact field name instead of column index.
Beware that such filtering is not-secure and if you need to hide some data - be sure to define such limitation on server side, not as part of URL.
APPLICABLE TO: Grid, TreeGrid, Combo
To enable server-side filtering you can use one of the following in-header filter types while configuring dhtmlxGrid/dhtmlxTreeGrid on client-side:
mygrid.setHeader("Column A, Column B"); mygrid.attachHeader("#connector_text_filter,#connector_select_filter")
Usage text filter doesn't require any additional configuration code. Grid/TreeGrid will automatically send data about new entered text and filter server-side data using %mask% pattern.
If you need to change filtering pattern or implement more advanced logic - beforeFilter event should be used.
function custom_filter($filter_by){ //WHERE some_field LIKE 'value' if (!sizeof($filter_by->rules)) $filter_by->add("some_field","value","LIKE"); } $conn->event->attach("beforeFilter","custom_filter");
function custom_filter($filter_by){ if (!sizeof($filter_by->rules)) $filter_by->add("some_field","value","LIKE"); //change WHERE some_field LIKE '%value%' to the WHERE some_field > 'value' $index = $filter_by->index("some_field"); if ($index!==false) //there is client side input for the filter $filter_by->rules[$index]["operation"]=">"; } $conn->event->attach("beforeFilter","custom_filter");
By default, grid/treegrid will use DISTINCT select against related field, and fetch all possible options.
If you need to define custom list of options you can use one of 2 ways:
$grid->set_options("item_nm",array("1" => "1", "2"=>"two","3" => "3")); $grid->render_table("grid50","item_id","item_nm,item_cd");
$filter1 = new OptionsConnector($res); $filter1->render_table("countries","country_id","country_name(value)"); $grid->set_options("item_nm",$filter1); $grid->render_table("grid50","item_id","item_nm,item_cd");
You can use both render_table and render_sql methods for OptionsConnector object, the same as for any normal connector.
Beware that name of field, used in select filter need to have alias (value).
APPLICABLE TO: Grid, Combo
By using beforeRender events it's possible to define filtration rules as PHP code ( won't work for dyn. modes ).
function custom_filter($data){ if ($data->get_value("some")<0) $data->skip(); //not include in output } $conn->event->attach("beforeRender","custom_filter");