dhtmlxconnector:sort [DHX documentation]

PHP Connector DHTMLX

Sorting

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 column by specifying additional parameters in URL.
Check article Extending functionality for full url parameters description.

//ORDER by field_2 ASC
grid.load("some.php?connector=true&dhx_sort[2]=asc");
//ORDER by field_2 ASC, field_3 DESC
grid.load("some.php?connector=true&dhx_sort[2]=asc&dhx_sort[3]=desc");

sorting type 'connector'

APPLICABLE TO: Grid, TreeGrid

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

grid.setColSorting("connector,str,na");

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

By assigning to sorting type 'connector' you just 'say' that sorting will be implemented on server-side.
To define the way, 'behaviour' of sorting you should use beforeSort event.
Event doesn't allow to write custom sorting logic, but you can affect SORT BY clause of generated SQL request.

default sorting by one field

function custom_sort($sorted_by){
          //SORT BY some_field ASC
          if (!sizeof($sorted_by->rules)) 
               $sorted_by->add("some_field","ASC");
}
$conn->event->attach("beforeSort","custom_sort");

default sorting by multiple fields

function custom_sort($sorted_by){
          //SORT BY some_field ASC, some_other ASC
          if (!sizeof($sorted_by->rules)){
               $sorted_by->add("some_field","ASC");
               $sorted_by->add("some_other","ASC");
          }
}
 
$conn->event->attach("beforeSort","custom_sort");

custom sorting rule

function custom_sort($sorted_by){
          // SORT BY LENGTH(some_field)
          $sorted_by->rules[0]["name"]="LENGTH(some_field)";
}
 
$conn->event->attach("beforeSort","custom_sort");