Prevent data grid from sorting

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ibe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sun Oct 04, 2009 12:15 pm

Prevent data grid from sorting

Post by ibe » Thu Nov 19, 2009 8:04 pm

How can I stop a datagrid from sorting when the user clicks in the column header. Removing the header is not an option as I need them. I don't want the column header to sort but need them to allow resizing columns. If possible, it's not obvious from the docs.

Ismo

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Wed Apr 08, 2009 11:54 pm

Prevent data grid from sorting

Post by dickey » Thu Nov 19, 2009 11:21 pm

Hello ibe,

Whilst not exactly answering your question, being able to reset sorting in the grid is related to your question and very useful especially when organising data before performing calculations on DataGrid values. It may negate the need to disable sorting, because you can reset whenever you like.

Code: Select all

on mouseUp
   -- reset sorting in grid
   set the dgProps["sort by column"] of group "DataGrid 1" to empty
end mouseUp
I have not had the necessity to disable sorting altogether, as I can restore/reset sort order before updates or other operations using the above method (and users love sorting), however I believe you may disable sorting by altering the column template of the DataGrid.

I hope this helps.

Kind regards, Andrew

ibe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sun Oct 04, 2009 12:15 pm

Post by ibe » Fri Nov 20, 2009 7:02 am

Finally found the answer. Just in case anyone else needs it, the simple way is to add the below code to the data grid script:
on SortDataGridColumn pColumn
end SortDataGridColumn

This will prevent all columns from sorting and changing the header appearance. I found the answer here:
http://revolution.screenstepslive.com/s ... n-Sorting-

which seems interesting for those who need specialized sorting.

Post Reply