[Gambas-user] Sorting gridviews

Tobias Boege taboege at ...626...
Wed Jun 25 13:51:42 CEST 2014


On Wed, 25 Jun 2014, B Bruen wrote:
> Someone, recently, was discussing sorting gridviews over multiple columns. Tobi?
> 
> Was any progress made on this?
> 

The project was finished some time ago. But likely the results will not
please you because the code is not very integrative.

Basically, we model the GridView as an array of Record objects (the array is
the rows, a Record describes the columns in the GridView). By a special
RecordArray class which Inherits Record[] and a special _compare() method in
Record, we can sort that RecordArray by any property of the Record objects.

So you must write a Record class for your specific purpose and have an array
of them behind the scenes to populate the GridView with. Maybe you can tweak
the code to be a bit more general... if you get it much more general, please
tell me :-) [ IIRC, we have a SortField property in each Record object which
we need to set for each object in the array before we sort. I think you can
replace that with a static property if you never sort multiple arrays at the
same time... ]

The code for the GridView is here[0] and also here[1] in the more abstract
context of sorting multidimensional arrays. (The project archives are at the
end of the article.)

Regards,
Tobi

[0] http://www.gambas-buch.de/dw/doku.php?id=k17:k17.7:k17.7.4:start
[1] http://www.gambas-buch.de/dw/doku.php?id=k7:k7.4:k7.4.9:k7.4.9.4:start

PS: I would prefer [1] over [0]. The code used in [0] was actually an early
try from me and it uses the officially not supported possibility to override
Variant[]. (Variant[] acts as both, a Record object and also as an array
class for Variant[] objects there!)

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list