Change sort order on browse when clicking on header

Change sort order on browse when clicking on header

Postby ellano » Sat Oct 06, 2018 4:42 pm

How do I interchange between a descending and ascending sort order in a Xbrowse?

Code: Select all  Expand view  RUN
 SELECT myfile
  DATABASE oDbfG
   //create temporary index
  oDbfG:CreateIndex( ,"NumberD","myfile->number", ,.T.,.T.)
  oDbfG:CreateIndex( ,"Number" , "myfile->number", ,   ,.T.)
  DEFINE DIALOG oDlg RESOURCE "Main" TITLE "Main" FONT oFont
    oDbfG:GOTOP()
    REDEFINE XBROWSE oBrw OF oDlg FONT oFuente COLOR RGB(0,0,0),RGB(226,241,254) ;
     AUTOSORT DATASOURCE oDbfG;
     FIELDS oDbfG:number
     ID 101 HEADERS "Number" ;
     SIZES           110
     
     WITH OBJECT oBrw
       :aCols[1]:cSortOrder := "number"
       :aCols[1]:oDataFont  := oFont
// Try this among dozen other combinations but will not work

       :aCols[1]:bLClickHeader := { || nOrden++, IIF(nOrden>2, {nOrder:=0, oBrw:oCol("number"):cSortOrder=Nil }, ;
                                                    IIF(nOrden=1, oBrw:oCol("number"):cSortOrder="number", ;
                                                                     oBrw:oCol("number"):cSortOrder="numberD" )   )  }
   END


Ascending sort is working when clicking on header, but will not change to descending or back to none.

Thanks
Emiliano Llano Díaz
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: Change sort order on browse when clicking on header

Postby nageswaragunupudi » Sat Oct 06, 2018 8:00 pm

Please try this sample. Click on header toggles ascending and descending orders.
That is the default behavior, if not modified in the application program.

Sample code:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDbf, oDlg, oBrw, oFont

   USE \FWH\SAMPLES\STATES NEW SHARED VIA "DBFCDX"
   DATABASE oDbf

   oDbf:CreateIndex( nil, "TMPCODE", "CODE", nil, nil, .T. )
   oDbf:CreateIndex( nil, "TMPNAME", "NAME", nil, nil, .T. )

   oDbf:SetOrder( "TMPCODE" )
   oDbf:GoTop()

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE DIALOG oDlg SIZE 400,500 PIXEL TRUEPIXEL FONT oFont

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf ;
      COLUMNS "CODE", "NAME" ; // do not use FIELDS clause
      SORT "TMPCODE", "TMPNAME" ;
      AUTOSORT CELL LINES NOBORDER

   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   oDbf:Close()

return nil


Image
Regards

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

Re: Change sort order on browse when clicking on header

Postby ellano » Sun Oct 07, 2018 7:02 am

As always, right on the point. Everything back to normal when changing FIELDS to COLUMNS. :D

My final example (in case someone is stuck):

Code: Select all  Expand view  RUN
 DEFINE FONT oFont NAME "ARIAL" SIZE 0, -16 BOLD
  Define FONT oFont1 NAME "ARIAL" SIZE 0, -14 BOLD

  Select IsActive
  SET ORDER TO TAG "ID"

  SELECT MyFile
  DATABASE oDbfG

   //create temporary indexes: CreateIndex( [cFile], cTag, cKey, [lUnique], [lDescend], [lMemory] )
  oDbfG:CreateIndex( nil,"Numbr", "MyFile->Numbr"                           , nil, nil,.T.)
  oDbfG:CreateIndex( nil,"cName", "Left(PADR(ALLTRIM(MyFile->cName),25),25)", nil, nil,.T.)
  oDbfG:CreateIndex( nil,"Born",   "DTOS(MyFile->fecnac)"                     , nil, nil,.T.)

  DEFINE DIALOG oShow RESOURCE "Show_Main" TITLE "Main" FONT oFont
    oDbfG:GOTOP()
    oDbfG:SetOrder("Numbr")

    // reserve column 5 for a bitmap
    REDEFINE XBROWSE oBrw OF oShow FONT oFont COLOR RGB(0,0,0),RGB(226,241,254) ;
       DATASOURCE oDbfG;
       COLUMNS "Numbr", "cName", "Born", "_", " " ;
       SORT    "Numbr", "cName", "Born", nil  , nil ;
       ID 101 HEADERS "ID","Name","Date","_","Active" ;
       SIZES           70,  220,    100,  70,    40 ;
       AUTOSORT CELL LINES NOBORDER
       
     WITH OBJECT oBrw
       :aCols[1]:oDataFont  := oFont1
       :aCols[3]:oDataFont  := oFont1

       :aCols[5]:AddResource( 'ON' )
       :aCols[5]:AddResource( 'OFF' )
       :aCols[5]:bBmpData:={ || IIF( IsActive->(DBSEEK(MyFile->Numbr)), 1, 2 ) }

       :bKeyDown :={|nKey| Move_Line(oShow, nKey, oBrw, cImages) }
       :bLDblClick := {|| Show_Register(cImages, oBrw) }
     END  

  ACTIVATE DIALOG oShow CENTERED ON INIT (HB_SYMBOL_UNUSED(self),;
                  Show_Bar(oShow,oBrw,@num,cImages))
  oFont:End()
  oFont1:End()


Thanks
Emiliano Llano Díaz
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: Change sort order on browse when clicking on header

Postby nageswaragunupudi » Sun Oct 07, 2018 7:28 am

Why show_bar() function ON INIT?

We can now create buttonbars for dialogs also just like in windows.
Regards

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

Re: Change sort order on browse when clicking on header

Postby ellano » Sun Oct 07, 2018 12:19 pm

You are right again. But in this particular case is because this depends on 3 different scenarios that I did not include on the sample:

In my program it something like this:

Code: Select all  Expand view  RUN
Show_Bar(aryFile,oShow,oBrw,@num,Company,cImages,nWhich)  //nWhich indicates the bar to display and options to hide or show
 
ellano
 
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 57 guests