Custom Sorting and Filtering

DataTable provides a built in mechanism for sorting columns, and the Paginator widget provides a means to filter the data by page number and results per page. When more complex sorting and filtering is required, a custom generateRequest may be needed, along with manually passing that generated request into DataSource's sendRequest method.

Sample Data:

CSS:

Markup:

Building the generateRequest Function

DataTable has a default generateRequest function. In order to create a custom query string, the generateRequest configuration setting must be overridden. Keep in mind that DataTable's column sort state needs to be taken into account, if using column sorting. This example does not use DataTable's built in column sorting. The comments in the code shows how to implement DataTable's column sorting.

The custom generateRequest function, this.requestBuilder, is passed in to the generateRequest DataTable configuration setting.

Sending the Request

The external sorting and filtering controls will need to initiate a request for new data. DataSource's sendRequest method requires a request string (the custom query string) and a callback object. The custom generateRequest function will provide the request string.

The callback has four properties that are very important here.

success
There are four methods built into DataTable for handling the success and failure events. Please refer to Loading Data at Runtime for a list of the four methods and a description of each. It should suffice to say that, onDataReturnSetRows is what is required for this example, because we are using the Paginator widget.
failure
Please see the success property above... The same applies here.
argument
DataTable's state -- getState() -- is passed as the argument. If any changes to the Paginator UI need to be done, those changes should be reflected in the state object. If the page needs to be reset to 1, that needs to be manually set. It's going to be your job to keep the Paginator in synch with the DataTable when calling sendRequest manually.
scope
Pass in an instance of the DataTable.

Handling the Response

Overriding DataTable's handleDataReturnPayload method allows the Paginator's totalRecords to be updated properly. That will enable the paginator to calculate how many pages of data there are. The bulk of the work is done for us automatically through the oCallback::success or oCallback::failure handlers set in the sendRequest method call.