Reorder data rows?

In the examples for Applescript Studio, there’s a little application called “table reorder.applescript”.

All it does is use this line:

set allows reordering of table view "table" of scroll view "scroll" of window of theObject to state of theObject

to allow for re-ordering rows in a Table View by dragging. However, I can’t seem to replicate this behaviour.

In the example, there’s a check box that’s connected to “on clicked” handler, and whenever the check box is clicked, the handler gets called and that statement you posted sets the state of “allows reordering” to whatever the state of check box is (1 or 0 which is basically the same as true or false).

This would work if you don’t use a check box:

set allows reordering of table view "table" of scroll view "scroll" of window "main" to true

That sets the “allows reordering” property to true. Remember to put correct object names there, otherwise it won’t work.

I hope this helps :slight_smile:

Never mind, I found it. This will only work if the data source is not ordered. Turns out that the data source by default will be ordered and you explicitly have to switch ordering off. But you have to do so before you give the “allows reordering” instruction.

This doesn’t work:

set allows reordering of tableView to true
set sorted of dataSource to false

But this does

set sorted of dataSource to false
set allows reordering of tableView to true

EDIT:
So now the problem is that the row doesn’t remain selected, or rather he selection doesn’t travel with the rows that are being dragged up or down.