xbrowse array autosort problem

xbrowse array autosort problem

Postby Richard Chidiak » Sun Aug 15, 2010 5:27 am

Hello

I need to sort a column of a xbrowse "at startup" as descending, I am browsing an array

The bitmap (for ascending, descending) is showing "descending" for the column but the column is not sorted

This is the code below ,

Thanks for the help,

Code: Select all  Expand view


REDEFINE XBROWSE oBrw ID 201 OF ODLG ;
         COLUMNS 2,10,5,3,4,7,11,12,13 ;
         HEADERS "Date" + CRLF + "Facture", "Fournisseur","N°" + CRLF + "Facture","Date" + CRLF + "Echéance","Date" + CRLF + "Paiement","Total" + CRLF + "TTC","Total" + CRLF + "Acomptes","Solde","Motif";
         FOOTERS ;
         FONT aFont ;
         COLORS {|| { CLR_BLUE, CLR_WHITE } } ;
         colsizes asize ;
         array TVISU lines AUTOSORT

oBrw:aCols[01]:cOrder := 'D'   // this is not working

 
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Sun Aug 15, 2010 12:44 pm

Instead of
Code: Select all  Expand view
oBrw:aCols[01]:cOrder := 'D'   // this is not working

Remove the above line and Substitute with
Code: Select all  Expand view

oBrw:aCols[01]:SetOrder()  // This works
 
Regards

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

Re: xbrowse array autosort problem

Postby Richard Chidiak » Mon Aug 16, 2010 5:42 am

Thank you Mr Rao

in order to have it descending , the following is needed also

oBrw:aCols[01]:CSORTOrder := 'D'
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Mon Aug 16, 2010 6:15 am

Richard Chidiak wrote:Thank you Mr Rao

in order to have it descending , the following is needed also

oBrw:aCols[01]:CSORTOrder := 'D'


NO PLEASE.

The solution I provided works correctly and that is the only way.

oCol:cSortOrder ( in case of arrays ) is the array element number on which to sort but not 'D' or 'A'.

oCol:cSort holds if it is "A" or "D", after it sorts in ascending or descending order. Let xBrowse handle this internally and let us not confuse xBrowse by handling this directly.

oCol:SetOrder() sorts the column, switching ascending to descending and vice-versa. When the browse is defined with AUTOSORT, the browse has already sorted on ascending order of first column.
When we call aCols[1]:SetOrder(), it sorts in descending order because it is already sorted in the ascending order.

Adopting my solution will give you the result required by you and please do not touch cSortOrder or cSort.
Regards

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

Re: xbrowse array autosort problem

Postby Richard Chidiak » Mon Aug 16, 2010 6:37 am

You are right sorting arrays confused me a bit ,

Can you please review the seekonarray function , in case of non sequential columns (like in my sample)

the following line will cause an error in this case, i have commented it as i always need to seek on upper values

if ! ::aCols[ nCol ]:lCaseSensitive // we get out of range in this case

Thank you for your help

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby James Bott » Mon Aug 16, 2010 7:08 am

Adopting my solution will give you the result required by you and please do not touch cSortOrder or cSort.


This is why instance vars such as these should be READONLY or even HIDDEN--so we can't mess with them.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Mon Aug 16, 2010 11:25 am

Richard Chidiak wrote:You are right sorting arrays confused me a bit ,

Can you please review the seekonarray function , in case of non sequential columns (like in my sample)

the following line will cause an error in this case, i have commented it as i always need to seek on upper values

if ! ::aCols[ nCol ]:lCaseSensitive // we get out of range in this case

Thank you for your help

Richard

Mr. Richard
You are right.
For the time being, it is better to comment out this if .... and corresponding endif.
Regards

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

Re: xbrowse array autosort problem

Postby Richard Chidiak » Mon Aug 16, 2010 2:23 pm

Mr Rao , i already did

when browsing an empty array with autosort, it errors, the correct fix for this is in the method setarray

And again when a column has no header or ablank header (only in browsing arrays) , xbrowse shows a character for the header, i go around this by setting a non visible char for the header....

Thank you for your help,

Richard

Code: Select all  Expand view


//      if lAutoOrder
      if lAutoOrder .AND. ! Empty( aData ) // this line in replacement of the above
         if ValType( aData[ 1 ] ) == 'A'

            DEFAULT nColOrder := ::aCols[ 1 ]:nArrayCol

            AEval( ::aCols, {|oCol| oCol:cSortOrder := oCol:nArrayCol, ;
                            If( oCol:nArrayCol == nColOrder, ;
                                 (oCol:cOrder := 'D', oCol:SortArrayData() ), ;
                                 nil ) ;
                            } )
         else
            oCol:cOrder := 'D'
            oCol:cSortOrder := 1
            oCol:SortArrayData()
         endif
      endif
   endif

 
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Mon Aug 16, 2010 4:19 pm

Mr Richard
when browsing an empty array with autosort, it errors, the correct fix for this is in the method setarray

You are right. This needs to be fixed.
Better fix seems to be
Code: Select all  Expand view
if Len( ::aCols ) > 1

And again when a column has no header or ablank header (only in browsing arrays) , xbrowse shows a character for the header, i go around this by setting a non visible char for the header....

If defining the browse in command mode, we may specify "" or " " in the HEADERS clause for the columns with blank headers.
Or after creating the browse, we may assign oCol:cHeader := '' or ' ' or nil
Regards

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

Re: xbrowse array autosort problem

Postby Richard Chidiak » Fri Aug 20, 2010 8:40 am

Mr Rao

oBrwI:aCols[01]:SETORDER() is working as expected , in my case the column is reversed to descending mode and this is what i want

Nevertheless, adding a new entry to the array of the browse will place the entry at the end of the list (not where it should be), i issue a obrw:refresh(.t.)after adding the entry.

if i reset a oBrwI:aCols[01]:SETORDER() before the refresh , then the line is placed correctly

The problem is that the sort order is reversed to ascending in this case... any clue ?

Thank you for your help

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Fri Aug 20, 2010 11:34 am

Please do this after adding a new line:
Code: Select all  Expand view

WITH OBJECT oBrw:aCols[ 1 ]
   :cOrder := If( :cOrder == 'A', 'D', 'A' )
   :SetOrder()
END
oBrw:Refresh()
 
Regards

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

Re: xbrowse array autosort problem

Postby Richard Chidiak » Sat Aug 21, 2010 4:22 am

thank you

Is there a way to know what was the column sorted by the user ?

I am using AUTOSORT and it could be any column, i need to refresh the "last sorted column"
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Sat Aug 21, 2010 4:41 am

Code: Select all  Expand view
nSortedCol := AScan( oBrw:aCols, { |o| !Empty( o:cOrder ) } )
oSortedCol := If( nSortedCol > 0, oBrw:aCols[ nSortedCol ], nil )
Regards

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

Re: xbrowse array autosort problem

Postby Richard Chidiak » Sat Aug 21, 2010 6:38 am

that does the job, thank you

Don't you think this code should be included in the refresh method when browsing arrays with autosort ?
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: xbrowse array autosort problem

Postby nageswaragunupudi » Sat Aug 21, 2010 6:45 am

Richard Chidiak wrote:that does the job, thank you

Don't you think this code should be included in the refresh method when browsing arrays with autosort ?

Sorting an array does consume some time, small or more, depending on the array size. Resorting is necessary only when a Row is added, which is not always the case. In the life-cycle of a large software this may become necessary in less than fraction of the total refreshes. It is therefore desirable for the programmer to handle it.
Regards

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 124 guests