Add new row
Add new row
karlie
Posts: 83Questions: 17Answers: 0
I want to add a new row in my table via a button and I have found this code
$(document).ready(function() {
var t = $('#example').DataTable();
var counter = 1;
$('#addRow').on( 'click', function () {
t.row.add( [
counter +'.1',
counter +'.2',
counter +'.3',
counter +'.4',
counter +'.5'
] ).draw( false );
counter++;
} );
// Automatically add a first row of data
$('#addRow').click();
} );
My table has 43 columns, do I need to add a counter for each column, or can it just be left blank if that cell doesn't require a value or a unique value? Only one of my columns is mandatory, and must be unique.
This discussion has been closed.
Answers
With
row.add()
you need to provide values for each column. They can be null or whatever but you will need an array with 43 elements.Kevin