How Do I Sort By A Column?
Using the Property Inspector
Select the data grid and open the property inspector. Navigate to the Columns pane (1), select the column you want to modify (2), and check the Sort by column checkbox (3).
Using Script
You can sort by column setting the dgProp["sort by column"] property of the data grid to the name of the column you want to sort by.
set the dgProps["sort by column"] of group "DataGrid" to "Name"
If you wish to include a sort direction, you can additionally set the dgColumnSortDirection[] of the group.
set the dgColumnSortDirection["Name"] of group "DataGrid" to "descending"
Note: Setting the dgColumnSortDirection[] alone will not change the chosen column to sort by. You do not however need to set this property last; it will be remembered when the sorted column is changed.
Ben
How do I change the direction of the sort using a script?
Gilar Kadarsah
Is there any way to make collum sort permanent? it mean, we update dataGrid by script (not user click), sort still work automatically. Yes it is there is sort by script above, but after update we have to run that script again and again and it make the speed slower. Thanks
Matthias Rebbe
Adding the following empty handler
on SortDataGridColumn pColumn
end SortDataGridColumn
to the Datagrid script should do what you want.
Matthias Rebbe
@Ben.Brannen
There are several ways to do it.
You can use the property dgColumnSortDirection
set the dgColumnSortDirection["col1"] of group "Data Grid" to "ascending"
possible values are ascending or descending
or you could use the command SortDataByKey
dispatch "SortDataByKey" to group "DataGrid 1" with pArrayKey, pSortType, pDirection, pCaseSensitive
where
pArrayKey is the columname
pSortType can be numeric,text,international, datetime
pDirection can be ascending, descending
pCaseSensitive can be TRUE, FALSE
Gilar Kadarsah
@Matthias Rebbe
I put this on dataGrid Script did not works for me
on SortDataGridColumn pColumn
end SortDataGridColumn
Matthias Rebbe
Hm,
i just tried it here again. Without that handler i can click on the columns header to sort and sorting works. If i add the two lines to my Datagrid script , then clicking on the columns headers to sort does not work.
Gilar Kadarsah
@Matthias Rebbe
Yes it mean disable Sort.
What I want to do is Sort Permanent. event data grid updated with this script
http://lessons.livecode.com/m/datagrid/l/7315-how-do-i-update-data-in-a-row
Matthias Rebbe
It seems i´ve misunderstood your origin question, please excuse. I am sorry, but i have no answer then for you, but i am sure someone of the Livecode stuff will answer.
Gilar Kadarsah
Hi @Matthias Rebbe ...
i appreaciate your comment
Elanor Buchanan
Hi Gilar
You should be able to resort after adding update the content by using the SoryByColumn command e.g.
dispatch "SortByColumn" to group "DataGrid" with "name"
I hope that helps.
Kind regards
Elanor
Gilar Kadarsah
Hi @Elanor Buchanan
I have tried this
dispatch "SortByColumn" to group "DataGrid" with "name"
but it make data grid slow,
FYI: my apps get data feed and update about 80 line/second.
so i update about 80 times / second
it feel slow when i have to run sort script every time update