xBrowse autosort 10.6 with object

xBrowse autosort 10.6 with object

Postby sambomb » Thu Mar 22, 2012 1:05 pm

Hi, I want to use the xBrowse autosort (for array) but when I use an object as an array the sort just don't work...

I put a debug in ACompare() and xVal and yVal is always numeric and 1, any tips?
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: xBrowse autosort 10.6 with object

Postby nageswaragunupudi » Thu Mar 22, 2012 5:51 pm

Please try
Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"

function main()

   local aObj, oDlg, oBrw, oFont

   aObj  := { ;
      TTemp():New( 1, 'One',   Date()     ), ;
      TTemp():New( 5, 'Five',  Date() + 2 ), ;
      TTemp():New( 3, 'Three', Date() - 3 )  }

   SET DATE ITALIAN
   SET CENTURY ON

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 400,200 PIXEL FONT oFont

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      FIELDS oBrw:aRow:nVal, oBrw:aRow:cVal, oBrw:aRow:dVal ;
      HEADERS "Number", "CharVal", "Date" ;
      SORT { |o| MyColSort( o ) }, { |o| MyColSort( o ) }, { |o| MyColSort( o ) } ;
      COLSIZES 50,100,100 ;
      ARRAY aObj CELL LINES NOBORDER AUTOSORT

   WITH OBJECT oBrw
      :nStretchCol   := STRETCHCOL_WIDEST
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil


static function MyColSort( oCol )

   local cOrder   := If( oCol:cOrder == 'A', 'D', 'A' )
   local oBrw     := oCol:oBrw
   local cData    := { "nVal", "cVal", "dVal" }[ oCol:nCreationOrder ]

   if cOrder == 'D'
      ASort( oBrw:aArrayData,,,{ |x,y| OSend( x, cData ) > OSend( y, cData ) } )
   else
      ASort( oBrw:aArrayData,,,{ |x,y| OSend( x, cData ) < OSend( y, cData ) } )
   endif

return cOrder


CLASS TTemp

   DATA nVal, cVal, dVal

   METHOD New( a, b, c ) CONSTRUCTOR

ENDCLASS

METHOD New( a, b, c ) CLASS TTemp

   ::nVal   := a
   ::cVal   := b
   ::dVal   := c

return Self
 
Regards

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

Re: xBrowse autosort 10.6 with object

Postby sambomb » Thu Mar 22, 2012 9:20 pm

Hi my structure is this:

Code: Select all  Expand view

   oRecto := TRecebimento():New()
   
   //-- xBrowse ----------------------------------------------------------//
   
   oBrx := TXBrowse():New( oDlg )
   oBrx:CreateFromResource( 301 )
   
   oBrx:lHScroll := .T. //-- 4/5/2011 - Aloizio.

   //-- Obs - aTitulos is an array of objects

   oBrx:SetArray( oRecto:aTitulos, .T. ,6, {5,6,3,9,10,21,22,8,16,23,27} )  

   xBrowseStyle(oBrx)  
   oBrx:nDataType := DATATYPE_ARRAY
   
   oBrx:bKeyDown := {| nKey, nFlags | KeyDownDlg(nKey, nFlags)}
   oBrx:bLDblClick := { || BtnClickMarcar() }    //---------------> Duplo click
   oBrx:bClrStd := { ||{CLR_BLACK,ClrPaneBrw()}} //---------------> Mudar cor de fundo


   oBrx:aCols[ 01 ]:cHeader := "Data emissao"
   oBrx:aCols[ 01 ]:nDataStrAlign := AL_CENTER
   oBrx:aCols[ 01 ]:nHeadStrAlign := AL_CENTER

   oBrx:aCols[ 02 ]:cHeader := "Data vencimento"
   oBrx:aCols[ 02 ]:nDataStrAlign := AL_CENTER
   oBrx:aCols[ 02 ]:nHeadStrAlign := AL_CENTER

   oBrx:aCols[ 03 ]:cHeader := "Título"
   oBrx:aCols[ 03 ]:nDataStrAlign := AL_LEFT
   oBrx:aCols[ 03 ]:nHeadStrAlign := AL_LEFT

   oBrx:aCols[ 04 ]:cHeader := "Valor a pagar"
   oBrx:aCols[ 04 ]:nDataStrAlign := AL_RIGHT
   oBrx:aCols[ 04 ]:nHeadStrAlign := AL_RIGHT

   oBrx:aCols[ 05 ]:cHeader := "Valor pago"
   oBrx:aCols[ 05 ]:nDataStrAlign := AL_RIGHT
   oBrx:aCols[ 05 ]:nHeadStrAlign := AL_RIGHT

   //-- valor original
   oBrx:aCols[ 06 ]:cHeader := "Vr. original"
   oBrx:aCols[ 06 ]:nDataStrAlign := AL_RIGHT
   oBrx:aCols[ 06 ]:nHeadStrAlign := AL_RIGHT

   //-- valor de devolução
   oBrx:aCols[ 07 ]:cHeader := "Vr. devolvido"
   oBrx:aCols[ 07 ]:nDataStrAlign := AL_RIGHT
   oBrx:aCols[ 07 ]:nHeadStrAlign := AL_RIGHT

   oBrx:aCols[ 08 ]:cHeader := "Retirado"
   oBrx:aCols[ 08 ]:nDataStrAlign := AL_LEFT
   oBrx:aCols[ 08 ]:nHeadStrAlign := AL_LEFT
   oBrx:aCols[ 08 ]:nWidth        := 170  

   //-- histórico.
   oBrx:aCols[ 09 ]:cHeader := "Histórico"
   oBrx:aCols[ 09 ]:nDataStrAlign := AL_LEFT
   oBrx:aCols[ 09 ]:nHeadStrAlign := AL_LEFT

   oBrx:aCols[ 09 ]:nWidth        := 200  

   //-- valor já recebido
   oBrx:aCols[ 10 ]:cHeader := "Vr. já pago"
   oBrx:aCols[ 10 ]:nDataStrAlign := AL_RIGHT
   oBrx:aCols[ 10 ]:nHeadStrAlign := AL_RIGHT
   
   //-- data do recebimento parcial
   oBrx:aCols[ 11 ]:cHeader := "Dt. parcial"
   oBrx:aCols[ 11 ]:nDataStrAlign := AL_RIGHT
   oBrx:aCols[ 11 ]:nHeadStrAlign := AL_RIGHT

 
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: xBrowse autosort 10.6 with object

Postby nageswaragunupudi » Fri Mar 23, 2012 1:30 am

You may assign a codeblock for each column
oCol:cSortOrder := { |o| YourSortLogic( o ) }

My sample illustrates the usage. It is upto you whether you like to use data names or data ordinal positions to fetch the values for sorting.
Regards

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

Re: xBrowse autosort 10.6 with object

Postby sambomb » Fri Mar 23, 2012 11:54 am

If is up to me, it isn't autosort.

8.02 works fine.
I think the error is here:

Code: Select all  Expand view

METHOD SortArrayData()  CLASS TXBrwColumn

   local aCols
   local cOrder
   local nAt, nFor, nLen
   local uSave, cType

   aCols  := ::oBrw:aCols
   cOrder := ::cOrder
   nLen   := Len( aCols )
   nAt    := If( ValType( ::cSortOrder ) == 'N', ::cSortOrder, ::nArrayCol )

   if Len( ::oBrw:aArrayData ) > 0

      for nFor := 1 to nLen
         if aCols[ nFor ]:nArrayCol != ::nArrayCol
            aCols[ nFor ]:cOrder := ""
         endif
      next

      uSave    := ::oBrw:aArrayData[ ::oBrw:nArrayAt ]
      if cOrder == 'A'
         ::oBrw:aArrayData := Asort( ::oBrw:aArrayData,,, {|x,y| ACompare( x, y, nAt, ::lCaseSensitive ) < 0 } )
         ::cOrder     := 'D'
      else
         ::oBrw:aArrayData := Asort( ::oBrw:aArrayData,,, {|x,y| ACompare( x, y, nAt, ::lCaseSensitive ) > 0 } )
         ::cOrder     := 'A'
      endif
      ::oBrw:nArrayAt   := AScan( ::oBrw:aArrayData, uSave )
      ::oBrw:Refresh()

   endif

return self

//---------------------------------------------------------------------------//

static function ACompare( x, y, nAt, lCaseSensitive )

   local nRet := -1
   local xVal, yVal, xType, yType
   local aType := 'ULNPDCHO'

   if ValType( x ) != 'A'
      x     := { x }
   endif
   xVal     := If( nAt <= Len( x ), x[ nAt ], nil )
   xType    := ValType( xVal )

   if ValType( y ) != 'A'
      y     := { y }
   endif
   yVal     := If( nAt <= Len( y ), y[ nAt ], nil )
   yType    := ValType( yVal )

   if xType == yType .and. xType $ 'CDLN'
      if xType == 'C' .and. ! lCaseSensitive
         xVal  := Upper( xVal )
         yVal  := Upper( yVal )
      endif
   else
      xVal  := At( xType, aType )
      yVal  := At( yType, aType )
   endif

   nRet  := If( xVal == yVal, 0, If( xVal < yVal, 1, -1 ) )
//-- xVal and yVal is always numeric 1
return nRet

 
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: xBrowse autosort 10.6 with object

Postby sambomb » Mon Mar 26, 2012 12:31 pm

Any tips?
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 110 guests

cron