1

I am working on this demo. How can I add JavaScript sourced data into an existing table?

I have seen this example on Datatables website but this looks like only one time process and in my case I need to truncate and load the dataset[] after each query add eventually add the result in the table as a new row.

$(document).ready(function () {
  var dataSet = ["Tiger", "Wood ", "Architect", "F15", "36", "Feb, 15"];
  $('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [
    'copy', 'excel', 'pdf', 'csv']
  });
  $("#addData").on("click", function(){
  });
});

1 Answer 1

2

You can use DataTables API to add rows.
You need to pass an array of values (columns):

var dt;

$(document).ready(function () {
    var dataSet = ["Tiger", "Wood ", "Architect", "F15", "36", "Feb, 15"];
    dt = $('#example').DataTable({
        dom: 'Bfrtip',
        buttons: [
            'copy', 'excel', 'pdf', 'csv']
    });

    $("#addData").on("click", function(){
        dt.row.add(["Whatever else"]).draw(false); 
    });
});

You can refer to this DataTables official example.

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.