Order by on multiple columns in grid.

Hi All,

I would like to have order by on multiple columns in the grid. Can anyone of you suggest me how to do that?

Thank you.

You’re in a developer forum. Are you trying to write code for sorting?

Once you make a column order by, it would effect all the remaining columns of the grid accordingly, So logically it seems not possible.

Yes. I would like to sort grid basing on multiple columns through code.

For example :

Name class rank

Giri 1 2

Shekhar 2 1

Mani 2 3

Praneeth 3 1

Prasad 3 2

Now i need to sort the grid by class descending and rank ascending.

output

Praneeth 3 1

Prasad 3 2

Shekhar 2 1

Mani 2 3

Giri 1 2

It’s easy - use QueryBuildDataSource.addOrderByField() multiple times.

For example, you could put code like this to datasource’s init() method:

this.queryBuildDataSource().addOrderByField(fieldNum(MyTable, Field1), SortOrder::Descending);
this.queryBuildDataSource().addOrderByField(fieldNum(MyTable, Field2));

Thank you Martin. It works…[Y]