{hero}

rows.add()

Since: DataTables 1.10

Add multiple new rows to the table.

Description

Adding new data to a table is central to the concept of being able to dynamically control the content of a DataTable, and this method provides the ability to do exactly that, adding multiple new rows at a time. If you wish to add only a single row at a time, this method's singular counterpart, row.add() can be used.

The rows that are added are subjected to the ordering and search criteria that are applied to the table, which will determine the new row's position and visibility in the table.

This method will add the data to the table internally, but does not visually update the tables display to account for this new data. In order to have the table's display updated, use the draw() method, which can be called simply as a chained method of the row.add() method's returned object - for example table.row.add( [ 1, 2, 3, 4 ] ).draw();. This is done to allow easy optimisation of the table where multiple rows can be added before the table is redrawn.

Type

function rows.add( data )

Description:

Add new rows to the table using the data given

Parameters:
Returns:

DataTables API instance with the newly added rows in its result set.

Examples

Add two new rows to the table and redraw:

var table = new DataTable('#myTable');

table.rows
	.add([
		{
			name: 'Tiger Nixon',
			position: 'System Architect',
			salary: '$3,120',
			start_date: '2011/04/25',
			office: 'Edinburgh',
			extn: '5421'
		},
		{
			name: 'Garrett Winters',
			position: 'Director',
			salary: '$5,300',
			start_date: '2011/07/25',
			office: 'Edinburgh',
			extn: '8422'
		}
	])
	.draw();

Add multiple new instances of an object to a table and then add a class to those newly added rows:

var table = new DataTable('#myTable');

table.rows
	.add([new Pupil(43), new Pupil(67), new Pupil(102)])
	.draw()
	.nodes()
	.to$()
	.addClass('new');

Related

The following options are directly related and may also be useful in your application development.