I am currently using jQuery datatables in one of my project. What I am stuck with is to be able to add a new row dynamically and at the same time add the row in alphabetical order position.
I understand that I need to use fnadddata from the API to add a row but this function only add the new row to the end of the table. It does not add according to alphabetical order. Hence I cook up my own code to find the position to add the row manually.
$(".rowList").each(function( ) {
if( $(this).text( ).toLowerCase( ) > eObj.response.name.toLowerCase( ) ) {
$(this).closest("tr").before( eObj.response.html ); // html is the new row from server
return false;
}
}
The code above find the alphabetical position and creates a new row in the table accordingly. But of course, as I'm not using datatables fnaddData function, once the row is added and when I click on some event on the table (For e.g: sorting, searching, filtering), the new row disappeared.
I understand this because of the DOM and cache issue of datatables. So is there a way for me to handle this?
Can't you just insert it at the end using fnadddata and then sort the rows based on the column's alphabetical value?
fnAddData most certainly does sort the table after it has run - example: http://live.datatables.net/aceyed/edit#javascript,html . Please link to a test case showing the issue.