How to make new Sort by click on header?

How to make new Sort by click on header?

Postby dutch » Sat Apr 12, 2008 2:47 pm

Dear Antonio,

I saw this in testxbr3.prg and able to new sort when click on header coloumn. How can I make new sort in browse when click on header?
Which code to anable new sort?

Regards,
Dutch

Code: Select all  Expand view
static function RddBrwAllColsDlg

   local oDlg, oBrw, oCol, cAlias := cGetNewAlias( "CUST" )

   USE CUSTOMER NEW ALIAS (cAlias) SHARED VIA "DBFCDX"
   SET ORDER TO TAG FIRST
   GO TOP
   MakeTotal()

   DEFINE DIALOG oDlg SIZE 800,400 FONT WndMain():oFont

   @ 10,10 XBROWSE oBrw ;
            OF oDlg SIZE 380,180 PIXEL ;
            ALIAS cAlias ;
            AUTOCOLS AUTOSORT

   XbrStyles( oBrw )
   AEVAL( oBrw:aCols, { |o| o:bPopUp := { |o| ColMenu( o ) } } )

   oBrw:lFooter      := .t.

   if !Empty( oCol := oBrw:oCol( "Salary" ) )
      oCol:bFooter  := { || nTotal }
      oCol:lTotal   := .t.
      oCol:nEditType := EDIT_GET
      oCol:bOnPostEdit := {| o, u, n| PostEditRDD( o, u, n ) }
   endif

   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED ON INIT oBrw:SetFocus()

   (cAlias)->( dbCloseArea() )

return nil
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby demont frank » Sat Apr 12, 2008 3:48 pm

Code: Select all  Expand view
FOR EACH el IN oBrw:aCols
   el:bLClickHeader := {|r,c,f,o|  ;
  oBrw:SortArray( o, oBrw:aArrayData ) } }
NEXT


i have changed method sortarray.

Each element from obrw:aArraydata has as last element a unique number (mostly a recordnumber) , so in the beginning from sortarray

LOCAL x := ATAIL(oBrw:aArrayData[oBrw:nArrayAt])

At the and :

oCol:oBrw:nArrayAt := ASCAN(oCol:oBrw:aArrayData,{|j|ATAIL(j)==x})

Frank
demont frank
 
Posts: 167
Joined: Thu Mar 22, 2007 11:24 am

Postby dutch » Sat Apr 12, 2008 5:19 pm

Deasr demont,

Can It be used SortArray() for database field not array data too?

Regards,
Dutch
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby nageswaragunupudi » Sat Apr 12, 2008 5:35 pm

From ver 8.03 onwards it is very easy to make sorting on any column very easy.

If we are browsing DBF ( or any RDD ), simply assign the index-tag to oCol:cSortOrder.

Example: oBrw:aCols[2]:cSortOrder := 'LASTNAME'

This is enough for the xbrowse to create all the necessary buttons, react to left click on the header, change the order and refresh the browse.

When we are creating the browse by commands, we can say ...
@ 0,0 XBROWSE oBrw ;
COLUMNS 'First', 'Second', 'City' ;
SORT 'First', 'Second'. ... etc ... ;
OF oWnd ALIAS 'CUST'

In case our index tag names are the same as field names, we can even simplify this by :

@ 0,0 XBROWSE oBrw COLUMNS 'First', 'Last', 'City' ... <etc>
OF oWnd AUTOSORT

Autosort clause tells the xbrowse to use index tag with the same name as the field name, if such an indextag exists.

Similarly in case of RecordSets, we can use AUTOSORT clause while creating the browse , or specify sort orders in the SORT clause of assign the sort order for any colum by oCol:cSortOrder := <order>.

Actually this reduces 20 lines of code for each column into a line or just one word.

Arrays:
Now the xbrowse provides simpler way to define array browses.

Simplest:
@ 0,0 XBROWSE oBrw OF oWnd ARRAY aData [AUTOFILL] [AUTOSORT]

AUTOFILL clause results in including all columns of array
AUTOSORT clause tells xbrowse to create sort code automatically.

If we want to browse only some of the columns we can write

@ 0,0 XBROWSE oBrw COLUMNS 5, 3, 4 OF oWnd ARRAY aData [AUTOSORT]

We can also say :
oCol := oBrw:AddCol()
oCol:nArrayCol := 3
// no need to write oCol:bStrData := { || cValToStr( aData[oBrw:nArrayAt][3]( }
// the value can be any datatype, we do not need to convert to char value
oCol:cSortOrder := 3 // automatically sorts on 3rd column
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby dutch » Sat Apr 12, 2008 6:45 pm

Dear nageswaragunupudi,

It means we can assign index tag to each column but if we create browse database without index tag, it can not re-sort the record.
Is it correct?

Regards,
Dutch
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby nageswaragunupudi » Sat Apr 12, 2008 7:00 pm

dutch wrote:Dear nageswaragunupudi,

It means we can assign index tag to each column but if we create browse database without index tag, it can not re-sort the record.
Is it correct?

Regards,
Dutch

The DBF should be having indexes.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 69 guests