Check documentation for the latest version of dhtmlxSuite Sorting DHTMLX Docs


There are 3 ways to implement server-side sorting:

The sort() method

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

$grid->sort("item_nm ASC");
$grid->sort("item_cd", "DESC");

URL manipulation

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

You can control how data will be sorted inside of a column by specifying additional parameters in URL.

Check the article Extending functionality for full url parameters description.

//ORDER by field_2 ASC
//ORDER by field_2 ASC, field_3 DESC

The sorting type 'connector'


To sort grid/treegrid content with connectors you need to use 'connector' as a sorting type during the grid initialization.


In the above code snippet the first column will be sorted on the server side with connectors, the second one as a string on the client side, the third column will be non-sortable.

By assigning to sorting type 'connector' you just 'say' that sorting will be implemented on the server side.

To define the way, 'behaviour' of sorting, you should use the beforeSort event.

This event doesn't allow writing a custom sorting logic, but you can affect SORT BY clause of the generated SQL request.

Default sorting by one field

function custom_sort($sorted_by){
    //SORT BY some_field ASC
    if (!sizeof($sorted_by->rules)) 

Default sorting by multiple fields

function custom_sort($sorted_by){
    //SORT BY some_field ASC, some_other ASC
    if (!sizeof($sorted_by->rules)){

Custom sorting rule

function custom_sort($sorted_by){
    // SORT BY LENGTH(some_field)
Back to top