Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sorting columns in a GRID datawindow...

403 views
Skip to first unread message

Troy Coombs

unread,
Nov 18, 2004, 4:59:00 AM11/18/04
to
I posted this to the General newsgroup, but should have posted it here.

I have this ability working in my application, but I would like to extend it
further. I would like to add the ability to sort multiple columns at the
same time by holding down the Shift key, similar to Outlook.

I had a code snipet for this a few weeks back but have since misplaced it.
Doh!!! I searched the newsgroups, CodeXchange & the Powerbuilder Web ring
but can't find it anywhere.

Does anyone have an example of this that they could share with me?

Troy


Troy Coombs

unread,
Nov 18, 2004, 8:03:33 AM11/18/04
to
I found it!

Here it is for anyone else that may which to have it.

Try this function. Call from clicked event from datawindow ->
uf_set_sort(this,dwo)

Will sort by clicked column, can perform secondary etc. sorts by clicking
[CNTRL] key and clicking another column.
Will resort if clicked again

/*********************************************************************
uf_set_sort
Description: Sorts dw based on text field clicked (called from datawindow
clicked event)
Parameters
adw Datawindow Control
adwo Datawindow Object
**********************************************************************/
String ls_sort, ls_new_sort
String ls_ad = 'A' //Defaults to Ascending
String ls_name, ls_column
Integer li_count
Integer li_return=0
String ls_type //001
String ls_prev_column
String ls_new_column
Boolean lb_multicolumn = FALSE
String ls_reverse
Integer li_pos

//multi-column.
//needs to appear first. Really needs to be in dw control but lack of
//datawindow object hierarchy forces it here
IF KeyDown(KeyControl!) THEN
lb_multicolumn = TRUE
END IF

//Did I click on text field ?
ls_name = lower(adwo.Name)
ls_type = upper(adw.Describe(adwo.Name+".Type")) //001
//IF Upper(adwo.Type) = 'TEXT' THEN //001
IF ls_type <> 'TEXT' THEN //001
RETURN 0
END IF

//Get the original datawindow sort
ls_sort = string(adw.Object.Datawindow.Table.Sort)
IF IsNull(ls_sort) OR ls_sort = '!' THEN
ls_sort = ''
ELSE
//Get previous column name
ls_reverse = Reverse(Left(ls_sort,Len(ls_sort) - 2))
li_pos = Pos(ls_reverse, ' ')
IF li_pos > 0 THEN //li_pos=0, then only column column is selected
ls_reverse = Left(ls_reverse, (li_pos - 1))
END IF
END IF
ls_prev_column = Reverse(ls_reverse)

//Get new column (text field follows columnname_t)
ls_new_column = Left(lower(ls_name), len( ls_name ) - 2)

//Check to see if new column exists in DW
FOR li_count = 1 TO Integer(adw.Object.Datawindow.Column.Count)
ls_column = lower(adw.Describe("#"+string(li_count)+".Name"))
IF ls_column <> ls_new_column THEN
CONTINUE
END IF
//Column exists

//check to see if it is same as previous clicked column
IF ls_column = ls_prev_column THEN
ls_ad = Right(ls_sort,1)
IF ls_ad = 'A' THEN
ls_ad = 'D'
ELSE
ls_ad = 'A'
END IF
//Just change the A/D on the end of the current sort
IF lb_multicolumn THEN
ls_sort = Left(ls_sort,Len(ls_sort) - 1) + ' ' + ls_ad
ELSE
ls_sort = ls_column + ' ' + ls_ad
END IF
ELSE
//Is this multi-column sort (by use of CTRL key)
IF lb_multicolumn THEN
//Append to current sort
ls_sort += ' ' + ls_column + ' ' + ls_ad
ELSE
//Replace sort
ls_sort = ls_column + ' ' + ls_ad
END IF
END IF

//Sort DW
adw.SetSort(ls_sort)
li_return = adw.Sort()
EXIT
NEXT

RETURN li_return

TO AUTO SCROLL THE DW IF A USER TRIES TO MOVE A COLUMN TO THE RIGHT:

This isn't an automatic feature - you'll have to code it yourself. It
wouldn't be that difficult, the dragleave event could detect the X/Y
position of the cursor relative to the datawindow, and trigger a horizontal
scroll in that direction.


"Troy Coombs" <coo...@quorumis.com> wrote in message
news:419c7264$1@forums-1-dub...

vsv

unread,
Nov 18, 2004, 4:36:49 PM11/18/04
to
Troy that is a good one, thanks.
Could you put in the codexchange & pfc OS.
also, it is shift key that works in Outlook.
vsv

"Troy Coombs" <coo...@quorumis.com> wrote in message

news:419c9da5$1@forums-1-dub...

0 new messages