Re: [Fxruby-users] Sorting an IconList
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <ly...@kn...> - 2004-03-06 02:38:20
|
On Feb 26, 2004, at 8:56 AM, Jamey Cribbs wrote: > Sorry if this question has been answered. I googled but did not find > anything... > > I'm trying to sort an IconList by the column that is clicked when the > user clicks a column header. OK. > If I use the sortItems method, it just sorts by the first column. Yes, this is indeed the default sorting method. To sort the items differently, you need to override the icon item's <=> method, as you would generally do for sortable Ruby objects. Of course, since this isn't documented, you would have a hard time knowing that ;) Please see the attached program for a contrived, but hopefully illustrative, example. ;) > I tried using sort_by: > > @iconlist.sort_by {|item| item.getText.split("\t")[@clickedColumn]} Remember that Enumerable#sort_by doesn't do an in-place sort, but rather returns a new array of the sorted items, e.g. # After this, anArray is still unsorted! sortedArray = anArray.sort_by { ... } > Is there a way to sort the IconList by anything other than the first > column? If you have additional questions after checking out the attached example, please let me know. And I'll try to add some docs for this the next time around ;) Hope this helps, Lyle |