Default/initial browse sort order

-Zigo-

Member
If you don't specify an initial sort field on a browse, what determines the initial sort order and how do you find out what it is programmatically?

It seems like Progress looks for any indexed fields (be it database table or temp-table) in the browse, and uses the first one it comes to within {&FIELDS-IN-QUERY-{&BROWSE-NAME}}. But without trawling through _File, _Index, etc. I can't see an easy way of finding out what it uses.

The reason I want to know is because I'm implementing a column sorting mechanism where the first click sorts ascending, the second sorts descending, and a third reverts back to the initial sort order.
 
Sort order on browse = sort order on underlying query.

Xref tells you what indexes are being used in Data access statements (although the code will tell you what the initial FOR EACH is - just restore that).

Lee
 

-Zigo-

Member
Thanks for your reply.

Please forgive me but I know little about Xref - it appears to be an option you choose when you compile something? I can't see how this is useful to my requirements.

I can find the FOR EACH statement but that doesn't tell me which index is used for sorting.
 
Sorry, I think I misled you a little by mentioning xref.


Your browse is based on a query, initially opened (for the browse) with an OPEN QUERY statement, eg.

1) OPEN QUERY q-cust FOR EACH customer <WHERE/SORT options>.


The browse will initially display records in the order returned by that query (that order in turn defined by the indexes on the tables in the query, and the WHERE/SORT options defined - you can determine these indexes using xref, although it's not necessary here).

If when a browse column is clicked you re-open the query in a different order, to restore the order to the initial setting, re-open the query again using the intitial OPEN QUERY statement in 1) above.


Since typing the above, I notice the sample code you have supplied looks like it is AppBuilder generated, and you may even be using some version of ADM. Even so, the principle is the same, even if the coding is slightly different.


HTH

Lee
 

-Zigo-

Member
Yes I am using ADM1 and the AppBuilder. It &SCOPE-DEFINEs some variables for the query, like {&OPEN-QUERY-{&BROWSE-NAME}} which contains the entire "OPEN QUERY ... FOR ... " etc. statement.

I am trying to write some generic code to put in an include file that will work on all browses. See my other thread (http://www.progresstalk.com/showthread.php?t=84094) for more information about that. This means that any query in question could be sorted by anything.

As I stated in my first post in this thread, I want to allow a 3rd sort on a column to revert back to the original sort order - but only if this results in something different to sorting ascending on the column that was clicked.

Example: say I have 3 columns - surname, first name and age. If there is no initial sort-by phrase set up, then the browse will be sorted by an index if there is one (I don't know how it does it if there are no indexes). Say surname is the indexed field, therefore by default it will be sorted by surname. If the user clicks the surname column, I want to know whether to sort ascending or descending, by determining what the default (initial) sort order is and whether an ascending sort on surname gives the same result. In this example, I would like a first click to sort on surname descending (since it was already sorted ascending), then a second click to sort on surname ascending again, and so on. However let's say that the default index is on surname+age. If I sort on the surname column then this is a different sort because it's only using one field, hence I would like the first click to sort on surname ascending, the second click on surname descending, and a third click to revert back to the default.

If you followed that then I hope you can see what I mean when I say I would like to know programatically what the default sort order is.
 
My short answer: I don't think you can retrieve the Initial sort order programmatically via a Progress method call.

My long answer:

The only way I can think of retreiving initial sort-order dynamically is to store the initial query string in your Initialise Object section. This is essentially the same as I have suggested previously, but in a dynamic environment.

For static browses, try storing "{&QUERY-STRING-{&BROWSE-NAME}}" on initialise. (Although you may be able to retrieve this at any point during program - I haven't tried). This is normal Appbuilder code - you will need to experiment with code preview for ADM1 specifics.
Of course, you are already aware of OPEN QUERY scoped variable, so I suspect this doesn't help much.


Some more dynamic functions:

I've never used ADM1, but perhaps you can find equivalents to the following ADM2 functions:
getQueryString
getQuerySort

There is also a BaseQuery property in ADM2, but I am unfamiliar with it.

Additionally, there is an Index-Information attribute for general query objects, if you ever want to determine indexes used.

Sorry I was unable to give you a more helpful answer.


Lee
 

lord_icon

Member
Adm

Obviousley you have never used ADM / ADM1. The equivelants you requested do not exist. ADM2 is a whole new concept, PSC used ADM(1) as a dry-run. It were a really good concept - the local idea. However it has all now (for a long time) been binned. ADM 2 is the future, why even try to learn equivelants of a dinosaur? Be like Progress - dynamic, Progress for tomorrow - TODAY
 

-Zigo-

Member
Thanks for the help. Unfortunately I can't just switch to ADM2 - there is a small matter called this company that I work for...

For practically everything else, ADM1 does the job that we need - I guess I'm just being a bit too 'adventurous' and should just stick to something a bit simpler.
 
Top