Add a row to a DataTable using jQuery

To add a row to a DataTable using jQuery, you can use the row.add() method. Here's an example:

var table = $('#myTable').DataTable();
var data = ['John', 'Doe', 'johndoe@example.com'];

table.row.add(data).draw();

In this example, myTable is the ID of the DataTable, data is an array containing the data for the new row, and draw() is called to redraw the table with the new row added.

You can also add a row using an object instead of an array. Here's an example:

var table = $('#myTable').DataTable();
var data = {
  first_name: 'John',
  last_name: 'Doe',
  email: 'johndoe@example.com'
};

table.row.add(data).draw();

In this example, data is an object containing the data for the new row, and the keys correspond to the column names in the table.

Komentar

Postingan populer dari blog ini

Node.js Telegram Bot API send an image with text

Node.js Telegram BOT retrieve data from API

WhatsApp Web login QR code in an HTML page using whatsapp-web.js