sort on a Grid by not using display method

Hi people

I’m having a problem here, I know that I can’t sort on a grid using a display method. Now on filters I created a dropdown and two buttons: SortAscending and SortDescending. Mission is to populate the dropdwon with the fields on the grid that need to be sorted and when a user clicks on that dropdown and select a field, then must click on the button next to it that’s labelled SortAsc/ SortDesc, then the selected field must be sorted on that particular order

Please help.

Thanks in advance.

Sinoyolo

You can’t sort by display methods - they’re defined in AX application and SQL database can’t use them in queries. You’ll have to use another approach - a join, a calculated field, a view, a temporary table or anything what is applicable in your case.

Hi Martin

Thank you for your response.

Yes I’m aware of the fact that I can’t sort using a display method, hence I created a combo box on the filters that will contain the fields to be sorted and the 2 buttons that are Ascending and Descending.

I want a user to select a field from a combo, then click on one of the buttons to enable sorting, but will only sort by only the selected field, until it’s changed to another field.

On each button I have a clicked method where I put this:

void clicked()
{
APMMemoryNoteTable curMemNoteTable;

str Name, Surname;
;

super();

curMemNoteTable.data(APMMemoryNoteTable);

// APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenFirstName), SortOrder::Ascending);

////f (sortAsc::clicked)
//{
// switch(status)
// {
// case Name:
// APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenFirstName), SortOrder::Ascending);
// break;
// case Surname:
// APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenFirstName), SortOrder::Ascending);
// break;
// }
//}
APMMemoryNoteTable_ds.executeQuery();
AxnSAMCCJobTypeWorkCentres_ds.executeQuery();
AxnSamCCJobTypeQualifyResources_ds.executeQuery();

APMMemoryNoteTable_ds.research(true);
AxnSAMCCJobTypeWorkCentres_ds.research(true);
AxnSamCCJobTypeQualifyResources_ds.research(true);

if(curMemNoteTable.RecId)
{
APMMemoryNoteTable_ds.findRecord(curMemNoteTable);
}
}

The commented lines, are the lines I’m struggling with, I wanted to do a switch statement to cater for each field in the combo that is selected to sort by it.

I hope you get what I’m trying to explain, not really good in explaining.

thanks

Sinoyolo

Sorry Sinoyolo, I didn’t get what you’re trying to do. As I understand, you know how to sort datasource but you don’t know how to write the switch statement.

I don’t know what you have in your status variable, but it seems that you have a field name there. Your switch would work if Name and Surname weren’t empty, you would need to assign field names (or what is coming in status) to them - for example, you could use str name = fieldStr(AxnSAMMemoryNoteCCLines,CitizenFirstName) (you’ll probably want to get rid of the variables completely).

Hi Martin

Thanks I got it, I can post it if I have to.

str sortField;
;

super();

sortField = SortBySelection.valueStr();

curMemNoteTable.data(APMMemoryNoteTable);

if(sortField != ‘’)
{
switch(sortField)

{

case “Name” :
APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenFirstName), SortOrder::Ascending);

break;
case “Surname” :
APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenLastName), SortOrder::Ascending);
break;

}

}

Thanks again

Sinoyolo

Hi Martin

Thank you, I finally got it right [:D]

A few additions and edits were required:

str sortField;
;

super();

sortField = SortBySelection.valueStr();

curMemNoteTable.data(APMMemoryNoteTable);

if(sortField != ‘’)
{
switch(sortField)
{
APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenFirstName), SortOrder::Ascending);
break;
case “Surname” :
APMMemoryNoteTable_ds.query().dataSourceTable(tablenum(AxnSAMMemoryNoteCCLines)).addSortField(fieldnum(AxnSAMMemoryNoteCCLines,CitizenLastName), SortOrder::Ascending);
break;

}

}

Thank again[:)]

Sinoyolo

Hi Sinoyolo

If we are using normal form it is ok for filtering. I am using a list page and using a display method to display product & now as per myrequiremnt i need to apply on sorting for that field.

Any one help me with the problem of sorting on display method field in a list page.