rowReorder - can i send dragged row id?

rowReorder - can i send dragged row id?

paweltrelapaweltrela Posts: 25Questions: 10Answers: 0
edited July 2020 in Free community support

Hello,

I am using rowReorder and everything works fine.
I just would like to know.

Is it possible to send row which i dragged through the API edit call?
My ajax endpoints looks like this and i am passing there some custom params.
Is there way to add there some parameter with dragged row?

I know that when i use rowReorder it sends my all row params, but i need directly row which i dragged.

            ajax: {
                create: {
                    type: "POST",
                    url: '<%= path %>',
                    data: function ( d ) {
                        d.board_id = '<%= @board.id %>';
                        d.user_id = <%= current_user.id %>;
                    }
                },
                edit: {
                    type: "PATCH",
                    url: '<%= path %>'+"/_id_",
                    data: function ( d ) {
                        d.board_id = '<%= @board.id %>';
                        d.user_id = <%= current_user.id %>;
                    }
                },
                remove: {
                    type: "DELETE",
                    url: '<%= path %>'+"/_id_",
                    data: function ( d ) {
                        d.board_id = '<%= @board.id %>';
                    }
                }
            },

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    This example shows how to setup RowReorder with Editor.
    https://editor.datatables.net/examples/extensions/rowReorder.html

    Kevin

  • paweltrelapaweltrela Posts: 25Questions: 10Answers: 0

    @kthorngren yes, i know but everything in my case works fine.
    When i move my row, all rows involved in this process are sent to backend.

    But my backend doesn't know which row was directly dragged and moved.
    All rows are 'asc' ordered.

    I need to know which row was clicked by the user and dragged into another place :)

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    I believe you can use the row-reorder event for that information. The detail parameter has a node object which I believe is the dragged row.

    Kevin

  • paweltrelapaweltrela Posts: 25Questions: 10Answers: 0
    edited July 2020

    @kthorngren, thank you, i've checked it and it was row-reorder event.

    When i use:

            .on( 'row-reorder', function ( e, diff, edit ) {
                console.log(edit.triggerRow.data().DT_RowId);
            });
    

    i receive an id of the row i clicked.

    But is there easy way to send it to the backend like a normal parameter within an edit ajax call?
    The only way i am thinking now is just pass it to the session parameters and call it on the backend side.

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Possibly you can use the Editor's preSubmit event to add the row_id. I'm guessing it follows after the row-reorder event. Not sure without testing though.

    Kevin

This discussion has been closed.