Datatables add new row callback

In DataTables, you can add a callback function to be executed when a new row is added to the table. This callback is called row.added and it is triggered after the new row has been added to the table.

Here is an example of how to use the row.added callback:

$('#myTable').DataTable({
  "data": [...],
  "rowCallback": function(row, data, index) {
    $(row).on('added.dt', function(e, settings) {
      // Code to be executed when a new row is added
      console.log('New row added!');
    });
  }
});

In this example, the rowCallback function is used to attach an event listener to the added event of each row in the table. When a new row is added to the table, the event listener will be triggered and the code inside the callback function will be executed.

You can also use the row.added callback to perform some action on the new row, such as setting some default values or triggering some other event.

For example:

$('#myTable').DataTable({
  "data": [...],
  "rowCallback": function(row, data, index) {
    $(row).on('added.dt', function(e, settings) {
      // Set some default value for the new row
      $(row).find('input[name="myInput"]').val('Default value');
    });
  }
});

In this example, when a new row is added to the table, the callback function will set the value of an input field with the name myInput to Default value.

You can also use the row.added callback to trigger some other event, such as a custom event or a jQuery event.

$('#myTable').DataTable({
  "data": [...],
  "rowCallback": function(row, data, index) {
    $(row).on('added.dt', function(e, settings) {
      // Trigger a custom event
      $(document).trigger('newRowAdded');
    });
  }
});

In this example, when a new row is added to the table, the callback function will trigger a custom event called newRowAdded. You can then listen for this event in your JavaScript code and perform some action when it is triggered.