How Do I Disable Column Sorting?
This lesson will show you how to disable column sorting in a Data Grid table.
Sort By No Column

To begin, make sure you set the sort by column property to empty. This will remove any column sorting that might be active.
set the dgProp["sort by column"] of group "DataGrid 1" to empty

Your table headers should now appear the same, with no highlights or sorting arrow.
Edit Data Grid Script

Edit the Data Grid group script by right clicking on the Data Grid and selecting Edit Script.
Add SortDataGridColumn Handler

When the user clicks on a table column header the SortDataGridColumn message is sent to the Data Grid. By intercepting the message and not passing it you will effectively disable sorting. For more information about how SortDataGridColumn works please see this lesson.
Add the following code to your Data Grid group script and compile.
==========
Copy & Paste
==========
on SortDataGridColumn pColumn
end SortDataGridColumn

Now when you click on the table header the data will not be sorted.
Note: Once you add the SortDataGridColumn handler to a Data Grid setting the dgProp["sort by column"] property will no longer do anything. If you need to set the "sort by column" property later on you would need to remove the SortDataGridColumn handler from the script, or at least pass the message.
Jerry
Great tutorial, is it also possible to have just the firt column activated and all others de-activated?
Elanor Buchanan
Hi Jerry
Yes, this is possible. In the SortDataGridColumn you can check the pColumn parameter, if you want to allow sorting by that column pass the SortDataGridColumn message, if not do nothing.
For example if you want to allow sorting by the Code column but not by the State column your handler would be
on SortDataGridColumn pColumn
if pColumn is "code" then
pass SortDataGridColumn
end if
end SortDataGridColumn
I hope that helps.
Kind regards
Elanor
Jerry
Super!
Thanks very much Elanor!