// Initialize Datatable $(document).ready(function() { //$("#body").hide()…
- User
// Initialize Datatable (document).ready(function() { //("#body").hide() $('#myTable').DataTable({ data: [], columns: [ { data: 'date' }, { data: 'agent' }, { data: 'buyer' }, { data: 'price' }, { data: 'address' } ] }); });
// Function to add a new row to the table function addRow(date, agent, buyer, price, address) { console.log(date); console.log(agent); console.log(buyer); console.log(price); console.log(address); var table = ('#myTable').DataTable(); console.log(table); table.row.add({ date: date, agent: agent, buyer: buyer, price: price, address: address }).draw(); } addRow('01/01/2022', 'John Doe', 'Jane Doe', '100,000', '1234 Main St.');
I'm using datatable
for some reason the addRow function is console.logging the correct data its just not adding to the table and updating
- Assistant
It seems that you have initialized the DataTable with an empty
dataarray. You can update the initialization to include the default row data or add the row after the DataTable has initialized. Here's a modified version of your code that should add the row to the table: