Page 1 of 1

Sort groups by another field

Posted: Mon May 17, 2010 9:36 am
by sbaxter
Its posible to sort the report groups by other field that is not the group field? For example, I have a report that shows the invoices grouped by ClientId. The groups are ordered by the ClientId but I want to have the option to sort the groups (not the data) by the ClientName depending of a variable.

ClientId: 11 ClientName: Client B
Invoice 1
Invoice 2
Invoice 3
ClientId: 24 ClientName: Client A
Invoice 1
Invoice 2
Invoice 3

or by name

ClientId: 24 ClientName: Client A
Invoice 1
Invoice 2
Invoice 3
ClientId: 11 ClientName: Client B
Invoice 1
Invoice 2
Invoice 3


For the moment, I've created this method and called from the GroupHeader condition "{SortGroups()}":

Code: Select all

public string SortGroups()
{
    // sortByClientName is a dictionary variable
    if (sortByClientName)
        // Adding CLIENTID makes the groups unique because some clients have the same name
        return MYDATATABLE.CLIENTNAME + MYDATATABLE.CLIENTID;

    return MYDATATABLE.CLIENTID.ToString();
}

If I solved my problem why I'm asking? Well by 2 reasons, first is I avoid write code in the reports and I can't find a way to configure this from the designer.
Second, to share it with all.

Any sugestions?

Regards,

Scott.

Sort groups by another field

Posted: Tue May 18, 2010 2:04 am
by Jan
Hello Scott,

Yes it possible. At first you need remove sorting from group. Set SortDirection property of GrouppHeaderBand to None. After then set required sorting to Databand.

Thank you.

Sort groups by another field

Posted: Tue May 18, 2010 2:56 am
by sbaxter
Hi Jan,

I tryed that but without a luck, maybe I'm doing something wrong. The report shows only one group. I tryed with this:

* GroupHeader1
- Conditions=[No conditions]
- Sort Direction=None
* Data1
- Sort by "IIF(sortByClientName==true, MYDATATABLE.CLIENTNAME + MYDATATABLE.CLIENTID, MYDATATABLE.CLIENTID)"
- Then by "MYDATATABLE.DATE"

The invoices in the group are sorted by date.


Regards,

Scott.

Sort groups by another field

Posted: Tue May 18, 2010 7:33 am
by Jan
Hello Scott,

Please assign condition to GroupHeaderBand.

Thank you.