DHTMLX Docs & Samples Explorer

Index
dhtmlxgrid

## Step 4 - Add Client Side Sorting

To enable sorting of rows on the client side (“client side” means that grid will do this in your browser without using any help from the server) you need to define sorting type for each column in grid using mygrid.setColSorting(sortTypesStr); method, where sortTypesStr is a list of types. There are four types available plus “na” - which means that sorting is not available for the column:

- str - sort values as strings;
- int - sort values as integers (generally as any number);
- date - sort values as dates;
- custom sorting - this is a more complex type which gives the ability to sort values as you like (for example to sort days of week).

For example, we are going to sort the first column as string (str), the second as number (int) and set no sorting for the third one. In this case we need to add the following line of code before mygrid.init();

        mygrid.setColSorting("str,int,int");

Now you can click on the column header and sort the rows in grid according to the sorting types you've just specified. You can find out about "custom sorting".

If you run the page now and click on the last column header grid should look like this: