Monday, December 15, 2014

Sorting records



Sorting records

Sorting is the most important thing when display the data to the user. The user mostly prefers sorting functionality in the grid forms. AX 2012 has inbuilt functionality to sort the records in the grid by simply clicking the header of the grid column. Multiple sorting is not supported in the AX 2012. For example sort the fields by class and student name. Only single field sorting functionality is working in AX 2012.
As per the below example, we need to sort the record by student name. So, we should add some code in the form datasource init methd like below.


public void init()

{

    super();
    this.query().dataSourceNo(1).addSortField(fieldNum(Hari_ExamResult, StudentName), SortOrder::Ascending);

}


We can also clear the sorting functionality by calling the form datasource sortClear method like below.

void clicked()

{

    Hari_ExamResult_ds.query().dataSourceNo(1).sortClear();

    Hari_ExamResult_ds.executeQuery();

    super();

}


We should call the form datasource execute query to reflect the changes.

We can change the sorting field by using the below code.
First, clear the existing sorting field then add new sorting field.

void clicked()

{

    Hari_ExamResult_ds.query().dataSourceNo(1).sortClear();

    Hari_ExamResult_ds.query().dataSourceNo(1).addSortField(fieldNum(Hari_ExamResult, Standard), SortOrder::Ascending);

    Hari_ExamResult_ds.executeQuery();

    super();

}

 

We can use this code logic to achieve some sorting related business requirement

No comments :

Post a Comment