I have a list of line items in a table form a remote data source. Each line item represents a task to perform. I need a way to rearrange the line items, move an item up or down in the table rows. Then I will run a schedule program that will calculate the start dates of each line item.
Can someone give advise and example on how to do this? I already have the table of line items.
When the user clicks on an up-arrow control in the table (except on the first row), the event listener swaps the array entry corresponding to the clicked row with its predecessor. Then it calls the function that replaces the table with the new one.
Similar functionality for moving in the other direction.
I think it's just easier to keep the array sorted, and create the table from the array, than to try to sort table rows in the DOM.
If you don't really need the sorted data (for later submission for example), and you are just doing this for visual effect, you could also use the brute force approach of dis-attaching the clicked row from the table, and re-attaching it after the predecessor/successor.