Sorting on a field when another field is being sorted
-
Sorting on a field when another field is being sorted
Posted by DSC Communities on May 30, 2019 at 11:11 am-
Levi Stewart
MemberMay 30, 2019 at 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
—————————— -
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
——————————
——————————————- -
Levi Stewart
MemberJune 17, 2019 at 5: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
——————————
——————————————- -
Steeve Gilbert
MemberJune 3, 2019 at 8: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
——————————
——————————————- -
Levi Stewart
MemberJune 17, 2019 at 5: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
——————————
——————————————- -
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
——————————
——————————————- -
Levi Stewart
MemberJune 18, 2019 at 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
——————————
——————————————- -
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
——————————
——————————————-
DSC Communities replied 6 years, 10 months ago 1 Member · 0 Replies -
-
0 Replies
Sorry, there were no replies found.
The discussion ‘Sorting on a field when another field is being sorted’ is closed to new replies.