Group sorts are added automatically when a group is
added. You cannot add or remove a group sort independently from a group.
However, you can modify the group sort, for example, to change the sort
direction.
Retrieve the
DataDefController object.
DataDefController dataDefController = rcd.getDataDefController();
Find a field to sort on.
The
IDataDefinition.getResultFields
method returns all fields that have been added to the report design. This
example assumes that the report design contains a
Country field that
is called from a table named
Customer.
Fields resultFields = dataDefController.getDataDefinition().getResultFields();
Field sortField = (Field)resultFields.findField("{CUSTOMER.COUNTRY}", FieldDisplayNameType.formulaName, java.util.Locale.ENGLISH);
Retrieve the
GroupSortController object.
GroupSortController groupSortController = dataDefController.getGroupSortController();
Create a new
ISort
object, set the field to sort on with the
setSortField
method, and set the direction of the sort.
ISort newSort = new Sort();
newSort.setSortField(sortField);
newSort.setDirection(SortDirection.descendingOrder);
Call the
modify
method of the
GroupSortController class to
add the new sort to the report based on the chosen field.
The first parameter of the
modify
method specifies the sorting definition to be modified. The second parameter
specifies the new sorting definition.
groupSortController.modify(oldSort, newSort);
Example:
The following code modifies a sorting definition to
a report based on the field
Customer.Country.
void modifyGroupSort(ReportClientDocument rcd) throws ReportSDKException
{
DataDefController dataDefController = rcd.getDataDefController();
Fields resultFields = dataDefController.getDataDefinition().getResultFields();
Field sortField = (Field)resultFields.findField("{CUSTOMER.COUNTRY}", FieldDisplayNameType.formulaName, java.util.Locale.ENGLISH);
GroupSortController gsc = dataDefController.getGroupSortController();
ISort oldSort = gsc.findSort(sortField);
if (gsc.canSortOn(sortField))
{
ISort newSort = new Sort();
newSort.setSortField(sortField);
newSort.setDirection(SortDirection.descendingOrder);
gsc.modify(oldSort, newSort);
}
}