I want to populate data in DataTable on a button click by default the table should show no data.

I want to populate data in DataTable on a button click by default the table should show no data.

adninjazzadninjazz Posts: 4Questions: 2Answers: 0

_I am using NodeJs _

home.js

$(document).ready(function() { Table = $('#ctsdataTable').DataTable( { "ajax": "js/data.txt", "columns": [ {"data": "session_date"}, {"data": "session_number"}, {"data": "r_session_number"}, {"data": "account"}, {"data": "amount"}, {"data": "check_number"}, {"data": "tran_code"}, {"data": "isn"} ] }); });

home.ejs

`<button id="SearchButton" class="btn btn-info">Search</button>

Session Date Session No. R_Session No. Account Amount Check No. Tran Code ISN
Session Date Session No. R_Session No. Account Amount Check No. Tran Code ISN

`

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You would need to remove the ajax option from your Datatable init code and initialize to an empty table. Your button click event can then use jQuery's Ajax to request the data and in the Ajax Success function use rows.add() and draw() to add the data to Datatables.

    Kevin

This discussion has been closed.