Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting columns in my NSTableView



Graham Savage wrote:
| I have a Cocoa-Java app.
| I need to be able to sort columns by clicking the header and for the
| header cell to indicate the sorted column by remaining highlighted and
| possibly using a triangle indicator to show sort direction, just like
| iTunes does.
| I cannot find any documentation on sorting in tables, so do I have to
| sort myself in the tableViewObjectValueForLocation method after
| listening for a click on a column header cell?

The order of data in a table is determined *entirely* by what's returned by the table's data source when the table asks it "what's in cell x,y?". The table view itself doesn't even know what's in the table (that's what the data source is for), so it can't very well do any sorting. Nor does it have any way of knowing what the "right" order for each column is. All that means that the view itself *can't* control the table order.

Because the data source determines what's in each row and column of the table, to change the order of the displayed data, you change what the data source returns for the various cells in the table. Usually, the most straightforward way is to keep the data sorted in whatever order you want it in, but there are other approaches. (For example, you might keep several indexes into your data, and use the appropriate index for the current table order.)

So, the short answer is, yes, you're responsible for doing the sorting yourself after the user clicks the column header. I'd expect the easiest way to do things would be to reshuffle the table data in the table delegate's tableViewMouseDownInHeaderOfTableColumn() method. tableViewObjectValueForLocation() really shouldn't have to worry about that; by the time it gets called, the data should already be in the desired order.


Have you considered posting your questions to the cocoa-dev list, where the Cocoa experts hang out?

Glen Fisher
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Sorting columns in my NSTableView (From: Graham Savage <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.