rowReorder reset?

rowReorder reset?

th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

I am using colReorder and I have a button that resets the coulmns back to their original position using colReorder.reset(). I would like to do the same for rowReorder but I cannot find a comparable reset. How do I reset the rows back to their original position without having to refresh the page?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    The RowReorder docs explain that the rows are reordered by performing a data swap of the dataSrc column. You will need to come up with a method to keep track of the original dataSrc values. I would look at having two columns with the initial dataSrc values with the first being assigned the dataSrc and the other remain unchanged. When reseting the reordered rows copy the original indexes to the dataSrc column and redraw the table.

    Kevin

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736
    Answer ✓

    Here is an example:
    http://live.datatables.net/manezuni/1/edit

    Kevin

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    Your example is great! One other problem I ran into was trying to hide the column I am using for datasrc. Seems the rowReorder doesn't work then. I am using the primary key 'id' for the datasrc but I didn't want to show it in the table.

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736
    edited February 2020 Answer ✓

    Row reordering doesn't work or the reseting of the rows doesn't work?

    Hiding the dataSrc column shouldn't matter. Can you provide an example showing the issue?

    You probably will need to be careful using the technique I showed with objects. If you have two id columns both will probably be "data swapped" causing the solution to not work. See here:
    http://live.datatables.net/punoxolo/1/edit

    You can change the visibility to see that row reorder continues working. Also change the second column to data: "id2", to see that is fixes the reset issue.

    Kevin

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1
    edited February 2020

    Before your example the rows wouldn't reorder when I hid the dataSrc column. When I get to work Monday I'll implement your example and try hiding the id column again. Thank you for help Kevin.

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    I'll have to revisit this at a later date. This isn't a must for my app but would be nice to implement at some point. Thank you again for your help and examples.

This discussion has been closed.