Answered Generic START-SEARCH code

Cringer

ProgressTalk.com Moderator
Staff member
I've been doing GUI Progress for years and have never used the START-SEARCH event! Oops. Evidently my colleagues haven't either. Is there generic code for getting column sorting working? The browses in question are built using a dynamic temp-table where each field is added as ADD-LIKE-COLUMN.

I should obviously add that I'm on v11.2, on Win7.
 

Osborne

Active Member
Does something like this do the job?:
Code:
DEFINE VARIABLE cQuery AS CHARACTER INITIAL "FOR EACH Customer NO-LOCK" NO-UNDO.
DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hCustomerBuffer AS HANDLE NO-UNDO.
 
FORM WITH FRAME X WIDTH 93 TITLE "BROWSE" 20 DOWN.
 
ASSIGN DEFAULT-WINDOW:WIDTH = 94.
 
CREATE BUFFER hCustomerBuffer FOR TABLE "Customer".
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hCustomerBuffer).
hQuery:QUERY-PREPARE(cQuery).
hQuery:QUERY-OPEN.
 
CREATE BROWSE hBrowse
ASSIGN X        = 5
       Y        = 10
       WIDTH    = 91
       DOWN      = 20
       QUERY    = hQuery
       FRAME    = FRAME X:HANDLE
       READ-ONLY = FALSE
       SENSITIVE = TRUE
       FONT      = 2
       ALLOW-COLUMN-SEARCHING = TRUE
TRIGGERS:
  ON START-SEARCH DO:
     DEFINE VARIABLE hSortColumn AS WIDGET-HANDLE.
     DEFINE VARIABLE hQueryHandle AS HANDLE NO-UNDO.
 
     hSortColumn = hBrowse:CURRENT-COLUMN.
     hQueryHandle = hBrowse:QUERY.
     hQueryHandle:QUERY-CLOSE().
     hQueryHandle:QUERY-PREPARE("FOR EACH CUSTOMER NO-LOCK BY " + hSortColumn:NAME).
     hQueryHandle:QUERY-OPEN().
  END.
END TRIGGERS.
 
hBrowse:ADD-LIKE-COLUMN("Customer.CustNum").
hBrowse:ADD-LIKE-COLUMN("Customer.Name").
hBrowse:ADD-LIKE-COLUMN("Customer.State").
 
VIEW FRAME X.
WAIT-FOR CLOSE OF THIS-PROCEDURE.
 
DELETE OBJECT hBrowse.
DELETE OBJECT hQuery.
DELETE OBJECT hCustomerBuffer.
 

Stefan

Well-Known Member
Also look at the SET-SORT-ARROW() method on the browse - it will add nice visual sorting clue(s) for the user.
 

Cringer

ProgressTalk.com Moderator
Staff member
Thanks Osborne - that's exactly the sort of thing I was after. And thanks Stefan too.
 

Cringer

ProgressTalk.com Moderator
Staff member
Also look at the SET-SORT-ARROW() method on the browse - it will add nice visual sorting clue(s) for the user.
How do I establish the index of the current column? I can get a handle to it browsehandle:current-column, but how do I establish what the index is of it so I can set the sort arrow?
 

oli

Member
My two cents...

- Do not forget to APPLY "END-SEARCH" TO hBrowse somewhere inside the "START-SEARCH" event.
- We can go a little bit further and search the predicate's BY clause for the column name to possibly alternate ASCENDING/DESCENDING when the user clicks twice on the same column.
 

Cringer

ProgressTalk.com Moderator
Staff member
Yeah I've implemented the ASC/DESC stuff. What does applying END-SEARCH achieve?
 
Top