Datatable removes rows reappear

Datatable removes rows reappear

Hydro0Hydro0 Posts: 4Questions: 2Answers: 1

Hi

I have a datatable with buttons and select plugin. I try to add a delete button to delete selected rows.

Here part of my code to init table :

    select: true,
    dom: 'Bfrtip',
    buttons: [
        {
            text: 'Editer',
            className: 'red',
            action: function ( e, dt, node, config ) {
                dt.ajax.reload();
            }
        },
        {
            text: 'Supprimer',
            action: function ( e, dt, node, config ) {
                dt.ajax.reload();
            },
            attr:  {
                id: 'deleteButton'
            }
        }
   ],

And here my function to delete rows :

    $(document).on('click', '#deleteButton', function(e){
        var rows = table.rows( '.selected' ).remove().draw(false);
    });

But when I select rows and hit delete, rows disappear for 1 seconds then come back.

I tried clear() instead of rows( '.selected' ), but same thing, all rows disappear for 1 secondes then come back.

I use a delete button on each row with :

table.row($this.parents('tr')).remove().draw(false);

And it works well, so why my button doesn't work to remove selected rows ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Without a test case it is impossible to say, but my guess is that you are using server-side processing? If so, you need to tell the server to remove the rows and then redraw the table.

    Allan

  • Hydro0Hydro0 Posts: 4Questions: 2Answers: 1
    Answer ✓

    I've found the problem.....

    Juste remove dt.ajax.reload(); from the button action.

This discussion has been closed.