Page 1 of 1

Xbrowse array autosort behaviour

Posted: Fri Mar 25, 2011 12:19 pm
by Richard Chidiak
Hello

Xbrowse does not behave the same way with the autosort clause when browsing a dbf or an array

I explain , with dbf if we click on the header of the column, the sort is done and then the display will start on the same record as it was but sorted on that particular column. Bseek is issued automatically with autosort

In case of arrays , when clicking on the header of a column , the autosort is performed and we are positioned on the top of the array and this is a bad behaviour. seekonarray is not invoked in this case

Any idea how to correct this ?

Thanks for the help,

Richard

Fwh 10.10 but the problem is the same with fwh 11.01

Re: Xbrowse array autosort behaviour

Posted: Fri Mar 25, 2011 2:43 pm
by nageswaragunupudi
In case of arrays , when clicking on the header of a column , the autosort is performed and we are positioned on the top of the array and this is a bad behaviour.
You are right. The current row should remain on the same row before sort.

Kindly apply this modification to xbrowse.prg.
Please locate the following line of code towards the end of METHOD SortArrayData() of TXBrwColumn:

Code: Select all

      ::oBrw:nArrayAt   := AScan( ::oBrw:aArrayData, uSave )
 
Please change this line as

Code: Select all

      ::oBrw:nArrayAt   := AScan( ::oBrw:aArrayData, { |a| a == uSave } )
 
We shall be glad if you can test and comfirm.

Re: Xbrowse array autosort behaviour

Posted: Fri Mar 25, 2011 3:09 pm
by Richard Chidiak
Mr Rao

Tested , the fix is correct.

Many thanks for your quick reply,

Best regards

Richard

Re: Xbrowse array autosort behaviour

Posted: Sun Mar 27, 2011 8:02 am
by Frank Demont
Richard , Nages :

Using Customer.dbf , index on FIELD->Last (column2 )

1) Ordering a dbf (using an index) and ordering a array (column) will not give the same results for equal fields when we look ar the recordnumber.
For 'Bink' we have 125 , 152 ,176 , 382 there is a subkey record number

In the array (first try ) : 152 , 176 ,382 , 125
second : 382 , 125 , 176 , 152
AT RANDOM !!!

2) When in the arraysort 'Bink' is searched to reset the browse , one from the 4 'Binks' is found (the first one in the ordered array)
This gives total wrong results when is clicked on a column as 'Married' (only .F. or .T.) . When the array is reset the first occurance from usave (.F. or .T.) is found , it has nothing to do with 'Bink" ! We have to combine this column with another to make it unique

Only with a subkey we can improve xbrowse . The results would be much better with a index on LAST + FIRST , but equal names (last+first) are still there . Search in 'Bink Gregory' gives one from the two.

For using subkeys with xbrowse see : http://forums.fivetechsupport.com/viewt ... =3&t=21153
Saving uSave and restoring it must be changed in MySetArray


Both problems can be solved with adding a column record number (or numbering the array)

In the DBF the indexexpression seems to be LAST + STR(RECNO()) , so in the array :

oBrw:aCols[2]:bOrder := {|a|TRIM(a[2])+STR(RECNO(),6)}

I will adapt the example in http://forums.fivetechsupport.com/viewt ... =3&t=21153 to have a working example

Frank



This key is unique . It would also be possible to save (usave) to the recnumber (sortarray)

I

Re: Xbrowse array autosort behaviour

Posted: Sun Mar 27, 2011 8:51 am
by nageswaragunupudi
Saving uSave and restoring it must be changed in MySetArray
No. uSave is not any value of any column. uSave is actually the pointer of the row array. So the same line will be shown after sort even if they are duplicate values.

Well, about uniqueness and to retain the same key order in the database, the programmer has to bring in uniqueness in his ownway.

This can be achieved by adding a key column at the end and assigning it as oCol:cSortOrder.

Example:
We are reading an array of 3 columns from customer.dbf FIRST, LAST, CITY.

We can add FIRST + STR(RECNO()) AS 4th column.

Construct browse for 1,2 and 3rd columns only. ( 4th column is not visible). But set aCols[ 1 ]:cSortOrder := 4.

Then the first column is sorted in the order of 4th column.

In the above posting, if we want the FIRST to be sorted on FIRST-LAST, then we may add FIRST-LAST as the 4th column in the above example.

From 11.1 onwards even array seek is on 4th column.

Re: Xbrowse array autosort behaviour

Posted: Sun Mar 27, 2011 9:10 am
by Frank Demont
Nages ,

I am using FWH 8.10 and tested :

1 ) Select BRINK (4 names) , Change between A and D several times , select item changes (between the for names)

2) click on married , no brinks more selected.

Sorry when it works now as expected

Frank

Re: Xbrowse array autosort behaviour

Posted: Sun Mar 27, 2011 9:33 am
by nageswaragunupudi
Mr. Frank

There have been a lot of improvements to fwh and xbrowse over these years. I have seen the code you posted in the other post.

All that would not be needed now.

Re: Xbrowse array autosort behaviour

Posted: Mon Mar 28, 2011 6:56 am
by Frank Demont
nageswaragunupudi wrote:Mr. Frank

There have been a lot of improvements to fwh and xbrowse over these years. I have seen the code you posted in the other post.

All that would not be needed now.
yes , i see now it is possible as described. Thank you very much for the explanation.

Personally i am convinced that using ::bOrder in TXBrwColumn is a more elegant solution. In mine example i have to add 6 columns with your solution.
Also the filosofy from a dbf with a indexexpression is present in arraysort and seek in ::bOrder , we can use the same filosofy
And , very few changes are to be made in xbrowse.

Frank