DataTable is defined as
var oTable = $(\'#table1\').dataTable({
\'aaData\': [
[\'John\', \'ABC\', \'$90000\'], [\'Doe\', \'XYZ\', \'$100000
Think you are too hasty to accept that you cant do what you want :) Of course it is possible, but it is hard to figure out under which circumstances. The question is not very specific. The following code inserts a new row just after the last row you have clicked :
var dataTable;
var options = {
bSort: false,
bPaginate: false
};
function initDataTable() {
dataTable = $('#example').dataTable(options);
}
function attachClickHandler() {
$("#example tbody tr").click(function(event) {
var index=$(this).index();
$("#insert").text('insert a row below the row you just clicked ('+index+')').attr('index',index).show();
});
}
$("#insert").click(function() {
var index=$(this).attr('index');
var newRow = ''+
'new '+
'new '+
'new '+
'new '+
'new ' +
' ';
dataTable.fnDestroy();
$("#example tbody tr").eq(index).after(newRow);
initDataTable();
attachClickHandler();
});
initDataTable();
attachClickHandler();
The idea is to insert the new row to the underlying DOM table, and then reinitialize dataTable when it is done. It works also by sorting, but for demonstration purposes I turn sorting off. As @scottysmalls mentions, dataTables is really sorting everything, so a new inserted row will immediately be sorted, and that would look like it was not inserted correct.
See demo -> http://jsfiddle.net/2AqQ6/