How to sort data on grid of form in AX 2012

In Microsoft Dynamics AX 2012 and Microsoft Dynamics 365 for Finance and Operations, grids are used very often on the form. If you want to sort data on grid of form in AX 2012 by ascending or descending orders. You are at the right place to learn.

The requirement is that I want to sort data on grid of form in AX 2012 when the form is opened. After successfully fulfilling the requirement in Microsoft Dynamics AX 2012, I planned to share my experience.

So, if you want to sort data on grid of form in Microsoft Dynamics AX 2012, you need to write two lines in the data source’s init() method after super() is called. Before starting, you should know the following:

Sr. #ElementRemarks about the the element
1.FormForm which contains the grid on which you want to apply sorting
2.FieldField in data source of form on which you want to apply sorting
3.Data sourceData source in form which contains the field on which you want to apply sorting
4.TableTable used in the data source of form

In my case, I have used the following:

Sr. #ElementElement name in AOT
1.FormSysDatabaseLog
2.FieldcreatedDateTime
3.Data sourceSysDatabaseLog
4.TableSysDatabaseLog

To implement the solution to sort data on grid of form in AX 2012, follow these steps:

  • Open the development work space

  • Go to AOT -> Forms -> FORM -> DATA SOURCE -> Methods

  • Override the init() method of data source if it does not exist, or, open the existing init() method

  • After super(), add the following code:

//Moeen Ahmed Sultan//It will clear if any other sorting is applied on the gridthis.queryBuildDataSource().sortClear();//It will add the sorting on the field//Use the table and field as per your own requirement in fieldNum function.//Use the ascending or descending order as per your own requirementthis.queryBuildDataSource().addSortField(fieldNum(SysDataBaseLog,CreatedDateTime),SortOrder::Descending);

Using the above two lines, you will be able to get the sorted data when the form is opened. In this way, you will achieve your requirement that is sort data on grid of form in AX 2012.

Blog: Click here

YouTube: Click here

GitHub: Click here


    Danzel
    Danzel管理员

    • 声明:本文由Danzel于2020-05-13转载(优化),转载须经原站同意并注明出处。
    • 本文地址:http://maryd.cn/?id=17
    上一篇:Deploy all AX2012 reports
    下一篇:Dynamics ax 2012 Cancel the reserved

    留言评论

    暂无留言
    取消
    扫码支持