This example shows a table that is sorted by descending age, then by ascending name
/** * * A simple method creates a sorted relational table. *
* @param list of data items in an information map.
* @param input data selection
* @return modified data selection
*
* @throws Exception
*/private com.sas.iquery.metadata.business.DataSelection SortedRelationalTableDisplay(java.util.List dsDataItems, com.sas.iquery.metadata.business.DataSelection query) throws Exception
{
//Sort items in the order given by the list.
java.util.List sortItems = new java.util.ArrayList();
for(int i = 0; i < dsDataItems.size(); i++)
{ com.sas.iquery.metadata.business.DataItem tdi = (com.sas.iquery.metadata.business.DataItem)dsDataItems.get(i);
String label = tdi.getLabel();
// Get columns to be sorted and apply sort
if ( label.equalsIgnoreCase("Age") )
{ tdi.setSortDirection(com.sas.iquery.metadata.business.DataItemActionType.SORT_DESCENDING);
sortItems.add(tdi);
}
else
if ( label.equalsIgnoreCase("Name") )
{ tdi.setSortDirection(com.sas.iquery.metadata.business.DataItemActionType.SORT_DESCENDING);
sortItems.add(tdi);
}
// Assign Column to all dataitems and add to dataselection.
query.addResultItem(tdi, com.sas.iquery.metadata.business.Role.COLUMN);
}
query.setSortOrderPrecedence(sortItems);
// Get data selection
return query;
}