Wednesday, 6 August 2008

Default Sorting of a Report

This was an interesting question:

"My requirement is Report should always display the original sequence (in the same way if I run the report in TOAD or SQL*PLUS, ...) and when I click the column heading then only it should do the actual sorting. Now, as soon as I set the sortable attribute to YES for a column and running the report for the first time... it's doing the sorting based on the that column."

So, how do you do that? Normaly, if you enable sorting on an apex report, it will save the sorting preference per user in an item and will call this preference next time you login.

I used the rownum to display the "original sequence" on initial load of the page and enabled the sorting on that column as well. Putting this column to be the first in the row on columns with enabled sorting and hiding it would do the trick. The second thing I did was to remove the sorting preference on the initial load and keep the rownum ordering as long as the user decides to sort the report.

You can view a working example here:

No comments: