While all connector can filter data by url manipulation, only Grid and TreeGrid1) has native GUI for sorting, so below info mostly actual for those two components.
To enable server side filtering you can use one of the following in-header filter types while configuring dhtmlxGrid:
mygrid.setHeader("Column A, Column B"); mygrid.attachHeader("#connector_text_filter,#connector_select_filter")
When using text filter, no any additional configuration necessary. Grid will automatically send data about new entered text and filter server side using %mask% pattern. If you need change filtering pattern or implement more advanced logic - beforeFilter server side event can be used
Event receives FilterInterface Object as parameter
Define default filtering
function custom_filter($filter_by){ //WHERE some_field LIKE 'value' if (!sizeof($filter_by->rules)) $filter_by->add("some_field","value","LIKE"); } $conn->attach->event("beforeFilter","custom_filter");
Redefine default filtering logic
function custom_filter($filter_by){ //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->attach->event("beforeFilter","custom_filter");
By using beforeRender events it possible to define filtering rules as PHP code ( will not 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")
If you are using select filter you may need to define list of options in select box, it can be defined in one of 3 ways
$grid->set_options("item_nm",array("1","two","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 for OptionsConnector object, same as for any normal connector.
Beware that name of fields, used in select filter need to have alias (value)