1

I'm using jQuery DataTables and adding rows after a successful insert to a DB. How can I force a refresh of the table? I have checked on docs but found only how to refresh if data is loaded with Ajax. I'm adding to the tbody client side.

1
  • I guess it depends upon how you're adding your new row? If you're adding it by adding the data via markup (adding a <tr> and one or more <td>s) then it should show but won't be registered with DataTables and thus won't be searchable, orderable and what have you. If you're adding it using the table.row.add(...row data...), method then all is good, just add draw() to the end so: table.row.add(...row data...).draw(). Hope that helps. Commented May 3, 2017 at 6:42

1 Answer 1

1

If you are using legacy datatable

      tableObj.fnClearTable();
      tableObj.fnAddData(data);
      tableObj.fnDraw();

also fnRedraw(), If you want to redraw the table

If you are using new Datatable then this may help you.

    var table = $('#example').DataTable();
    $('#myFilter').on( 'keyup', function () {
        table
            .search( this.value )
            .draw();
    } );


var table = $('#example').DataTable();

// Sort by column 1 and then re-draw
table
    .order( [[ 1, 'asc' ]] )
    .draw( false );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.