My datatable by default sorting for 1 column. Dynamically I am adding row to the table, row is adding sometimes in middle of table, sometime add to 2 page .. etc because first column is name.
But I want add top of the table or last of the table. Can we do that? How?
var t = $('#tblRoster').DataTable();
t.row.add( [memberCustomerName, memberPosition,memberMasterCustomer,
memberCustomerEmail, endDate,'<a href="#" class="linkbutton
padding-left-20" id="addCancelButton">Remove</a>']).draw( false );
My datatable by default sorting for 1 column. Dynamically I am adding row to the table, row is adding sometimes in middle of table, sometime add to 2 page .. etc because first column is name.
But I want add top of the table or last of the table. Can we do that? How?
var t = $('#tblRoster').DataTable();
t.row.add( [memberCustomerName, memberPosition,memberMasterCustomer,
memberCustomerEmail, endDate,'<a href="#" class="linkbutton
padding-left-20" id="addCancelButton">Remove</a>']).draw( false );
Share
Improve this question
edited Dec 20, 2016 at 15:20
Gyrocode.
58.9k16 gold badges156 silver badges191 bronze badges
asked Dec 20, 2016 at 3:53
James123James123
11.7k70 gold badges198 silver badges355 bronze badges
1 Answer
Reset to default 7Position of newly added data in entirely based on the ordering condition applied to the DataTable.
Suppose you want to add Row at last of the DataTable. So you need to take following steps:
Add New Row in DataTable.
Draw DataTable with specified order.
Move the page focus to last page of the DataTable (optional).
So you can achieve it this way.
$('#AddRow').on('click', function() {
var row = ['testing', 'testing', 'testing', 'testing', 'testing', 'testing'];
table.row.add(row).draw(false);
table.order([1, 'asc']).draw();
table.page('last').draw(false);
});
Here is its Demo