Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable sorting in NSTableVIew?

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.

like image 870
Omayr Avatar asked Nov 30 '10 07:11

Omayr


1 Answers

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."

like image 118
Yuji Avatar answered Nov 16 '22 01:11

Yuji