There are 2 ways to implement server-side sorting:
APPLICABLE TO:Grid, TreeGrid, Tree, Combo, Scheduler
You can control how data will be sorted inside of a column by specifying additional parameters in URL.
//ORDER by field_2 ASC
grid.load("some.do?connector=true&dhx_sort[2]=asc");
//ORDER by field_2 ASC, field_3 DESC
grid.load("some.do?connector=true&dhx_sort[2]=asc&dhx_sort[3]esc");
APPLICABLE TO:Grid, TreeGrid
To sort grid/treegrid content with connectors you need to use 'connector' as a sorting type during the grid initialization.
grid.setColSorting("connector,str,na");
In the code snippet above, 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.
class SortingBehavior extends ConnectorBehavior{
@Overrride
public void beforeSort(ArrayList<SortingRule> sorters){
sorters.add(new SortingRule("some_field","ASC"));
}
}
conn.attach.event(new SortingBehavior());
class SortingBehavior extends ConnectorBehavior{
@Overrride
public void beforeSort(ArrayList<SortingRule> sorters){
sorters.add(new SortingRule("some_field","ASC"));
sorters.add(new SortingRule("some_other","ASC"));
}
}
conn.attach.event(new SortingBehavior());
class SortingBehavior extends ConnectorBehavior{
@Overrride
public void beforeSort(ArrayList<SortingRule> sorters){
sorters.get(0).name = "LENGTH(some_field)";
}
}
conn.attach.event(new SortingBehavior());
Back to top