Server Side Filtering with jqxGrid using PHP and MySQL

This help topic shows how to implement server-side filtering with the jqxGrid widget. The Grid will request data from the server when the user applies a new filter or clears the filtering. The server-side script is going to deliver the data records in JSON format depending on the filter expression. We will obtain the data from Northwind Database and especially from the Orders table. You can download the Northwind database .sql script here and run it into MySQL to create the database. You can download the Northwind database .sql script here and run it into MySQL to create the database. The first thing we need to do is create the file we’ll connect with. We’ll call this file connect.php
Now we need to create the file that will run the query and bring the data so our Grid can be populated. We will call the file data.php.
In the above code, we create a query depending on the filter expression. The Grid sends the following data to the server: In the data.php, we check the value of the filterscount property. If there's a filter expression, the filterscount value will be greater than 0. Then we iterate through all of the applied filters.
The following code gets the value of the filter with index i.
$filtervalue = $_GET["filtervalue" . $i];
The following code gets the condition('Contains', 'Starts With', etc.) of the current filter.
$filtercondition = $_GET["filtercondition" . $i];
The current filter's column is stored in the 'filterdatafield' property.
$filterdatafield = $_GET["filterdatafield" . $i];
The filter operator specifies the relation of the current filter with the filters from the same column. Its value can be 0 for "AND" and 1 for "OR".
For example, if you have multiple filters applied to the same column the filter expression could mean the following ( filter all records in the 'First Name' column that start with 'a' and end with 'b'). The 'and' keyword is the filter operator.
$filteroperator = $_GET["filteroperator" . $i];

Depending on the value of the $filtercondition property, we build the query's WHERE clause.

The last step is to initialize the Grid. In order to enable the filtering, we need to reference the jqxgrid.filter.js and to set the Grid's filterable property to true. In the source object's initialization we override the built-in filtering by setting the filter member to a custom function. That function is called when the user changes the filtering expression by adding or removing a filter. In the filter function's implementation, we call the Grid's 'updatebounddata' method which makes a request to the server and passes the filtering parameters.