Add a new row to the top of the table.

Add a new row to the top of the table.

mbashokmbashok Posts: 1Questions: 0Answers: 0

I have created a method "addNewRow " for adding row to the top

$.fn.dataTableExt.oApi.addNewRow = function(oSettings, data) {
var that = this;
oSettings.oFeatures.bServerSide = false;
oSettings.oFeatures.bSort = false;
var rows = that.api().data();
that.api().clear();
that.api().row.add( data );
angular.forEach(rows, function(row, index){
that.api().row.add( row );
})
that.api().draw(false);
oSettings.oFeatures.bSort = true;
oSettings.oFeatures.bServerSide = true;
}

Example Usage

var table = $('table').DataTable();
var row = {name:'john', sex:'male'};
table.addNewRow( row);

This discussion has been closed.