How to disable sorting in NSTableVIew?
Asked Answered
B

1

9

I have a an NSTableView when ever I click on a specific header column the data in the table get reversed or sort upside down. I have checked NSTableView as well as NSTableColumn but couldn't find any method that disables this. I would be obliged if anyone can help in disabling this sorting on clicking on the header of a particular column.

Brena answered 30/11, 2010 at 7:8 Comment(6)
Damn, please don't prefix your question title with "[Objective C]". Not only are you missing a hyphen, but you are also missing the point. That's what tags are for.Defeasance
@ Jonathan: I would have appreciated, had you come up with some answerBrena
Do you use Cocoa Bindings? What are your settings?Terhune
@Terhune bindings, what for I think it has to do with the GUI i have an NSArrayController bound to it but I guess a GUI function has nothing to do with this .Brena
Well, it has lots to do with this ... :p Binding is too magical, you know. Before the days of bindings, the NSTableView didn't magically sort itself; we needed to implement it ourselves.Terhune
@Yuji, sorry buddy I underestimated your guess. You were right binding is really magical. Anyway thanks !Brena
T
37

Sorting of the NSTableView is done by its sortDescriptors, see here.

An NSTableColumn uses its sortDescriptorPrototype (see here) to generate the sort descriptor of the NSTableView, depending on how many times you clicked the column header, etc.

If you use dataSource to manage the data, then the sort descriptor is communicated via the delegate method tableView:sortDescriptorsDidChange:, see here. You just need to ignore the change message to stop sorting.

If you use Cocoa bindings to manage the data, the sort descriptor is generated by the table column and set to the NSArrayController. To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor."

Terhune answered 30/11, 2010 at 8:13 Comment(6)
Walaah ! that was awesome, I was using bindings and the problem is solved now. Thanks alot buddyBrena
thanks! how can To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor." be done programmatically??Fondue
You can create a property which always returns the same array of sort descriptors and bind the NSTableView to this property.Nf
> If you use Cocoa bindings to manage the data, the sort descriptor is generated by the table column and set to the NSArrayController. To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor." ......... I don't see this option on Xcode 8.xMarek
“You just need to ignore the change message to stop sorting” makes no sense. It's a delegate method, you implement it, how do you ignore it? Code example would have helped. -1.Autointoxication
@Autointoxication You just implement a delegate method which does nothing. It's no different from how to deal with your annoying neighbor who asks you to do many things: you reply "I'll do something" and actually does nothing :-)Terhune

© 2022 - 2024 — McMap. All rights reserved.