Moving a row to another position in the same table

I want to move a row to another position in the same table - the move should be reflected not only visually, but also in the real data source. I can think of 3 ways to do that:

  1. Re-construct the data rows of data source: I tried to directly manipulate data rows like this:

set data rows of data source of myTable to

but I got an error message. Also for very large table this is probably too slow.

  1. Swap adjacent rows so the row we want to move “bubbles up/down” to the target position. Again this is slow (linear complexity).

  2. Make a new data column to store ordinal numbers of rows and then sort the table using the column. This is very fast, but it only achieves moving visually. The real data rows is still a list of the original (unsorted) ordering.

Is there any other way to do this efficiently? Or did I miss anything in these methods?

Many thanks!

I notice you received no responses to this. Did you ever figure it out?

I, too, want to drag data rows to new positions in a table–as well as drag data items into other parent data items in an outline. Would you be able to shed any light?




Your question is actually two-fold:

  1. How to move table rows in a drag-n-drop fashion
  2. How to move a data row internally

Unfortunately I don’t have any answer to either of these - so far I just worked around them. For 1, I gave up on the fancy drag-n-drop idea, instead just providing two buttons to move a selected row up/down. This is just swapping two adjacent rows. For 2, I just do a series of row swapping to move a row to a non-adjacent position (like bubble-sort). Slow but easy to implement.

I too welcome any light being shed on these two puzzles.

(bow and return to the backstage)

Here’s my method of working with tables - hope it’s helpful.

I usually have the data for tables stored in a text file that my script reads as a list. When I manipulate data, it will re-order the list, re-write the text file, and then recreate the table.

Also, I use Acme Script Widgets.osax for working with lists.



Thanks for the pointer - Acme Script Widgets is not free (both in the sense of free speech and free beer).

For such small things like efficient list manipulation, we should really have a free tool somewhere. Kind of embarrassing.