Print Page | Close Window

Dynamic Mutli Sorting in CR2008

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=12710
Printed Date: 04 May 2024 at 8:33am


Topic: Dynamic Mutli Sorting in CR2008
Posted By: Ammu Thomas
Subject: Dynamic Mutli Sorting in CR2008
Date Posted: 24 Mar 2011 at 5:42pm
Hi
I am using Crystal report 2008 sp3 full build with hotfix 3.3 along with ASP.NET 2.0
I have implimented the multi field sorting using the record sort export and setting the sort order in the report designer.

Now my requirement is such that i would like to have dynamic sorting on multiple fileds while report is displayed in the UI.
Means suppose i have a report with Customer region,name,city,rating,status etc.

Now by using the sort control i would like to have the functionality in such a way that if user

a) first sorts on the region then the records should be first sorted by region
b) then sorts on the city then the records should be sorted first by region then by city
c) now sorts on the rating then the records should be sorted first by region ,second by city and then by rating

Now other user may do
a) first sorts on the rating then the records should be first sorted by rating
b) then sorts on the status then the records should be sorted first by rating then by status
c) now user sorts on the region then the records should be sorted first by rating,second by status and then by region

and so on the sorting criteria changes from user to user through the UI.

Is there any way to achieve the dynamic kind of sorting with Crytsal report 2008 where we can set the order of the fileds at sorting in UI dynamically .The sorting order of the fields are not known at the time of design of the report and its completely depends on the user's need.

Please let me know if you require any information on the same.

Thanks & Regards,
Ammu



-------------
Ammu



Replies:
Posted By: lockwelle
Date Posted: 28 Mar 2011 at 3:36am
while I have never used sort control, if the number of fields to sort by are finite and known you should be able to create a formula that will return a value that will allow you to sort dynamically.  This would be accomplished by grouping on the results of a formula.  For example: say your user enters region, city, ratings as the desired sort order, you could have a formula like:
 
local stringvar array str := split({?parameter}, ",");
local numbervar icount;
local stringvar sorted :="";
 
for icount = 1 to ubound(str) do(
  if str[icount] = "region" then sorted := sorted + {table.regionField} + "|";
  if str[icount] = "city" then sorted := sorted +{table.cityField} + "|";
  if str[icount] = "rating" then sorted := sorted +totext({table.ratingField}) + "|";
);
 
sorted
 
 
I may be off on the syntax for the 'for' loop, check help.  But that is the idea, bring a string, that should be unique as the result of a formula, then set the grouping to use the formula, and your report will be sorted.
 
HTH
 



Print Page | Close Window