How to add sorting in execute query to below code

Hi

I want to sort by also for my date column, how to add with this code

public void executeQuery()
{
    ;
    qbr = SysQuery::findOrCreateRange(jsProShipShipmentStatus_q.dataSourceTable(tablenum(jsProShipShipmentStatus)),fieldnum(jsProShipShipmentStatus,ShipDate));
    qbr.value(Sysquery::range(fromdate.dateValue(),todate.dateValue()));
    super();
}

Isn’t your code in jsProShipShipmentStatus data source? It should be, and it it is, you can replace this:

jsProShipShipmentStatus_q.dataSourceTable(tablenum(jsProShipShipmentStatus))

with this:

this.queryBuildDataSource()

Regarding sorting, consider simply setting Index property of the data source.

If you need it in code, use addSortField() method of QueryBuildDataSource. I assume you want to always sort by this field, therefore you should do it in init() (not in executeQuery()):

public void init()
{
    super();
    
    this.queryBuildDataSource().addSortField(fieldNum(jsProShipShipmentStatus, ShipDate), SortOrder::Ascending);
} 

i want to sort when we change from and to date once the grid is loaded i want to sort ascending

Unfortunately I’m not sure what you mean by this statement. Are you confirming that the solution works for you or are you indicating that you have a business requirement that isn’t covered by this solution? If it’s the latter, you’ll need to tell us what what the requirement is.