D365 Finance & Operations and Dynamics AX Forum

Expand all | Collapse all

Sorting on a field when another field is being sorted

  • 1.  Sorting on a field when another field is being sorted

    Posted May 30, 2019 11:11 AM
    I have two fields in my datasource, ETATime which is a string and shows on the grid and ETATimeSort which is a Timeofday and isn't showing on the grid but is in the datasource. ETATime is for showing a time with a +- numbers of days, as well as showing TBD when set to midnight. When the users are sorting on this field they aren't getting the desired functionality (naturally).

    Is there a way to sort my datasource on ETATimeSort when they select to sort on ETATime from the grid? Or at the very least the ability to pull out the fields a datasource is sorted on and get their direction so that field sort can be cleared and the sort can be moved to another field on the datasource WITHOUT clearing all the other sorting done on the grid?

    ------------------------------
    Levi Stewart
    Star Produce
    Saskatoon SK
    ------------------------------


  • 2.  RE: Sorting on a field when another field is being sorted

    TOP CONTRIBUTOR
    Posted May 31, 2019 08:57 AM
    Levi,

    I believe the only way to do something like this would be to hook into the executeQuery function of the datasource, loop through the fields and see which fields are currently being sorted, clear the sorts, then add back the ones you would like to keep.

    So for example, if columns A, B, and ETATime are sorted you would set the sorts to be A, B, and ETATimeSort instead.

    A simpler solution may be to just include ETATimeSort in the grid itself and let your users sort by it.

    ------------------------------
    Alex Meyer
    Director of Dynamics AX/365 for Finance & Operations Development
    Fastpath
    Des Moines, IA
    ------------------------------



  • 3.  RE: Sorting on a field when another field is being sorted

    Posted Jun 17, 2019 05:32 PM
    I tried this, and it almost works except I cannot find a way to determine the sort direction of a field. Do you know if this is possible?

    Everything in my code below fails:

    public static Set fields(FormDataSource _ds, int _tableNum)
        {
            Set fields = new Set(Types::Class);
            DictTable dictTable = new DictTable(_tableNum);
            for (int i = 1; i <= dictTable.fieldCnt(); i++)
            {
                DictField dictField  = new DictField(_tableNum, dictTable.fieldCnt2Id(i));
                if (!dictField.isSystem())
                {
                    FormDataObject field = _ds.object(dictField.id());
                    fields.add(field);
    
                    try 
    				{
                    //FieldId id = _ds.query().dataSourceTable(_tableNum).sortField(field.fieldId());
                    //SortOrder sortOrder = _ds.query().dataSourceTable(_tableNum).sortDirection(id);
                    //sortOrder = _ds.query().dataSourceTable(_tableNum).sortDirection(field.fieldId());
    				//SortOrder sortOrder = _ds.queryBuildDataSource().sortDirection(field.fieldId());
                    //SortOrder sortOrder2 = _ds.queryRunQueryBuildDataSource().sortDirection(field.fieldId());
    				}
    				catch
                    {
                    }
                }
            }
            return fields;
        }


    ------------------------------
    Levi Stewart
    Star Produce
    Saskatoon SK
    ------------------------------



  • 4.  RE: Sorting on a field when another field is being sorted

    SILVER CONTRIBUTOR
    Posted Jun 03, 2019 08:45 AM
    Hi Levi,

    There's a sort() method on the control.  You could try to override that, disable the super() call and add the sort field to the dataSource manually.  I've done this once with Ax2009.

    ------------------------------
    Steeve Gilbert
    Software Development Supervisor
    Boa-Franc S.E.N.C.
    QC, Canada
    ------------------------------



  • 5.  RE: Sorting on a field when another field is being sorted

    Posted Jun 17, 2019 05:34 PM
    I added in the override for the sort method on the grid column, and it never gets called. Is there anything else I need to do to make this override work properly when coding for d365?

    ------------------------------
    Levi Stewart
    Star Produce
    Saskatoon SK
    ------------------------------



  • 6.  RE: Sorting on a field when another field is being sorted

    TOP CONTRIBUTOR
    Posted Jun 17, 2019 09:05 PM
    Levi,

    I'm assuming you tested your code by putting a break point in you method and it's not getting hit?
    Is the method you created tagged as an 'override' method?
    Would you mind posting the code you currently have?

    ------------------------------
    Alex Meyer
    Director of Dynamics AX/365 for Finance & Operations Development
    Fastpath
    Des Moines, IA
    ------------------------------



  • 7.  RE: Sorting on a field when another field is being sorted

    Posted Jun 18, 2019 10:25 AM
    I tried break points and prints.

    Here is the code:
     [Control("String")]
        class starWarehouseOrdersTmp_ETADepartTime
        {
            /// <summary>
            ///
            /// </summary>
            /// <param name = "_sortDirection"></param>
            /// <returns></returns>
            public int sort(SortOrder _sortDirection)
            {
                int sort = super(_sortDirection);
                Info("sort");
                return sort;
            }
    
        }​


    ------------------------------
    Levi Stewart
    Star Produce
    Saskatoon SK
    ------------------------------



  • 8.  RE: Sorting on a field when another field is being sorted

    TOP CONTRIBUTOR
    Posted Jun 18, 2019 10:32 AM
    Levi,

    Your new method either has to override a default method that already gets called or have some eventhandler call your new method, otherwise it will never get called.

    Has one of the above options already been implemented?

    ------------------------------
    Alex Meyer
    Director of Dynamics AX/365 for Finance & Operations Development
    Fastpath
    Des Moines, IA
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role