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.
adninjazz
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 |
`
This discussion has been closed.
Answers
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 userows.add()
anddraw()
to add the data to Datatables.Kevin