DataMgr 2.5 Documentation: Change Sort Order

Change Sort Order

If you have a field in your table that you use for manual sorting of records (a "sort" or "ordernum" field, for example), DataMgr can make it easy to set the values for that field appropriately.

For example, consider the following table ("colors"):

ID Name sort
1 Red 1
2 Blue 2
3 Green 3
4 Yellow 4

If you queried this record and sorted by the "sort" field. The records would be in the following order: Red,Blue,Yellow,Green.

Now suppose you want to sort them: Green,Blue,Red,Yellow. Traditionally you might have to go into each record and change the sort value. If you create a user interface that passes a list of primary key values to DataMgr, however, it will take care of changing all of the values for you appropriately. Here is the syntax using DataMgr:

<cfset Application.DataMgr.saveSortOrder("colors","sort","3,2,1,4")>

This would result in the following data:

ID Name sort
1 Red 3
2 Blue 2
3 Green 1
4 Yellow 4

You don't have to have the numbering start with 1. If you want the numbering to start higher, just tell DataMgr how many records precede the ones that you are sorting. Let's suppose 15 records precede these (so you want the numbering to start with 16):

<cfset Application.DataMgr.saveSortOrder("colors","sort","3,2,1,4",15)>
ID Name sort
1 Red 18
2 Blue 17
3 Green 16
4 Yellow 19

Note that you need not pass in every record in your database. DataMgr will just assign values of 1 though n (where n is the number of records being sorted.