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:
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.
Swap adjacent rows so the row we want to move “bubbles up/down” to the target position. Again this is slow (linear complexity).
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?
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?
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.
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.