RowReorder with RowGroup

RowReorder with RowGroup

ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1

Link to test case : https://live.datatables.net/pesohuni/1/edit

In this example, I have set up DataTables with RowReorder and RowGroup. Additionally, there is a script that modifies the group (column "category") of a row where "commentaire" is set to "Oui" if it is dragged and dropped into another category.

However, there is a problem: when I drag and drop this row (or any other row from category 2, although there is no reason to because I don't want to change the category), the row {"11, category 1, no, Boat"} becomes {"3, category 1, no, Boat"}, thus changing the order... Why is this happening?

Thank you in advance for your help/answer,
Mathieu.

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    RowReorder works by swapping the rowReorder.dataSrc values. See the RowReorder docs for details.

    When you drag {13, category 2, non, Ceci est un commentaire} into category 1 it will get the index of the row where you drop it. All of the rows between where {13, category 2, non, Ceci est un commentaire} started and where its dropped have their indexes swapped. {"11, category 1, no, Boat"} becomes {"3, category 1, no, Boat"} because the row below it originally had index 3.

    For RowReorder to work properly the index column should be the first column sorted. Do this by changing orderFixed to orderFixed: [[0,'asc'], [1, 'asc']],. You will also need to change the starting indexes so category 1 are indexes 0 - 8 and category 2 are indexes 9 - 14.

    Moving {13, category 2, non, Ceci est un commentaire} into category 1 seems to works:
    https://live.datatables.net/pesohuni/2/edit

    Kevin

  • ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
    edited May 2

    You will also need to change the starting indexes so category 1 are indexes 0 - 8 and category 2 are indexes 9 - 14.

    that's no possible because i my application, data are added from a database and indexes are not set up for a perfect order like that, sometimes the user add an item with category 1 first, then category 2, then category 1 again... so in case of ur exemple that won't work because there will be many group category displayed and i only what 2 group category to be displayed...

    Any solution ?

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Are you looking for a solution to reorder the rows or just move rows between categories?

    Kevin

  • ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
    edited May 2

    I am trying to move rows between categories. For instance, I want to move row {13, Catégorie 2, oui, Ceci est un commentaire } to the first category without changing the order of row that shouldn't change.

    When I drag and drop that row bellow the row {11, Category 1, No, Boat}, {11, Category 1, No, Boat} should become {12, Category 1, No, Boat}. However, when I drag and drop it above, it should remain unchanged.

    Could you please provide a solution for this issue?

    Thank you in advance for your help.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    If you simply want to move rows between categories then it sounds like RowReorder is not the solution you want to use. You will need to create your own solution for this. I did this a long time ago between two tables. Checkout these two threads with examples:
    https://datatables.net/forums/discussion/52096/drag-and-drop-between-tables#latest
    https://datatables.net/forums/discussion/53609/html5-draggable-rows-between-datatables-example#latest

    Possibly you can refactor one of the solutions to work within one table between groups.

    Kevin

Sign In or Register to comment.