How to write code for sorting field in a grid in AX



How to sort in desc order a grid of a form

You put this code in the init methode of the datasource:


super()
this.query().dataSourceTable(tableNum(InventTable)).addSortField(fieldNum(InventTable, RecId),SortOrder::Descending);

http://microsoft-dynamics-ax-erp.blogspot.com/2011/10/how-to-sort-in-desc-order-grid-of-form.html


Assuming you are trying to sort field on datasource CustTable:
1) override modified() method on form control to call executeQuery() of the datasource
public boolean modified()
{
boolean ret;
;
ret = super();
CustTable_ds.executeQuery();
return ret;
}
2) override executeQuery() method on datasource to change sortorder before actual fetch of records
public void executeQuery()
{;
this.query().dataSourceTable(tableNum(CustTable)).addSortField(fieldNum(CustTable, RecId),SortOrder::Descending);
super();
}
Reference 

Sort Descending date on Grid


TECDeliveryOrderTable_ds.query().dataSourceTable(
tablenum(TECDeliveryOrderTable)).addSortField(
fieldNum(TECDeliveryOrderTable,InvoiceDate),
SortOrder::Descending);


Comments

Post a Comment