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?
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.