|
Return to Newsletter Contents...
Crystal Reports 2008 Sort Controls
by: Sean Beal, Senior Consultant, CRCP
Out with
the Old
Remember how
we used to have to do ‘dynamic’ sorting?
That’s right; we created parameters to allow the report consumer to
choose from available sorting options.
We could then use this parameter to drive a formula that returned a
particular field based on if – then or case logic.
Finally, we sorted on this formula.
The disadvantage of this methodology was mainly the fact that every time
a user wanted to view the report in a different way, a complete refresh and
re-query of the database was necessary.
It also just had a ‘hackish’ feel and could only be done if you knew how
to write formulas.
In with
the New
These
limitations have been resolved in Crystal Reports 2008 with the introduction of
the Sort Control. Let’s dive in and see how they work.
In order to do this, I’ve created a simple report based on the Xtreme
sample database, using the Invoice table.
It looks like this:

The report is
currently showing all data in the order in which it was entered into the
database. This is called
‘natural order’ or ‘original order’.
The first
step we need to take in order to allow users to dynamically change the sorting
of this report with Sort Controls is to add record sorting to the report using
the Record Sort Expert. This is no
different than how we used to add record sorting in the past; we’ll add it for
each field on which we want the user to be able to dynamically sort:

Choose
‘Ascending’ or ‘Descending’ sort directions on the fields depending on how you
want the initial sort state of the report to appear.
When finished, click ‘OK’.
Next, we need
to create the Sort Control itself.
We can do this one of two ways, using an existing text object (like a column
header), or by creating a new text object.
To use an existing text object, simply right click on the object, select
‘Bind Sort Control’, select the sort field to which you’d like to bind and click
‘OK’:


Repeat the
steps above for any additional fields on which you would like to allow users to
dynamically sort. Your report should
now look something like this:

Notice the
Sort Controls to the right of each text object selected.
Of course, clicking on them alternates the sorting for that particular
column.
There are
some limitations to note (these are mentioned in the Crystal Reports Online
Help). If your report has grouping,
the Sort Control will apply across the entire record set of the report; you
cannot sort within a group and leave other groups unaffected.
Sort Controls cannot be used in sub-reports, and cannot be created within
a Cross Tab or OLAP grid. Finally,
using Sort Controls will cause open drill down tabs to close.
Conclusion
Sort Controls
are an excellent replacement of the old parameter-formula method of providing
dynamic sorting. They have the
advantage of simplicity and do not re-query the database in order to re-sort the
report.
If you are already using Crystal Reports 2008 in your environment, you
owe it to your end users to check them out!
Go to Top |
Return to Newsletter Contents
|