How can i add a new row in a datatable?Which the dataTable contains the records ofajax return values
How can i add a new row in a datatable?Which the dataTable contains the records ofajax return values
![NirmalaSudhir](https://secure.gravatar.com/avatar/86254d3bdef1a38aa542dd22b790ab70/?default=https%3A%2F%2Fvanillicon.com%2F86254d3bdef1a38aa542dd22b790ab70_200.png&rating=g&size=120)
I have DataTable in my js file.
function getStudentDetail(id) {
//id is set globally
var oTableStudentDetails = $('#student_detail').DataTable({});
$('#btn-add-row').on( 'click', function () {
oTableStudentDetails.row.add([' ',' ',' ',' ',' ']).draw();
} );
}
Using this I can able to add the new row in the " $('#student_detail').DataTable({}); " datatable
I have to fetch some datas from the DB and i did get it in the DataTable. But after that i cant able to add new row in the dataTable just like before one.
function getStudentDetail(id) {
//id is set globally
var oTableStudentDetails = $('#student_detail').DataTable({
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"bLengthChange": false,
"dataType": "json",
"ajax": {
"url": url_prefix + "/getStudentDetail",
"data": function(d) {
d.idstudent = id;
}
}
});
$('#btn-add-row').on( 'click', function () {
oTableStudentDetails.row.add([' ',' ',' ',' ',' ']).draw(); //this is not working after using ajax value in DataTable
} );
}
When i try to add a new row I see that "Processing" but i cant able to add the new empty row. What am i doing wrong. Can anyone help.
The Result from the server side looks like this
{"aaData": [["1", "roshi", "sssss", "xxxxxxxxxxx", "xxxxxxxxxxx"]], "iTotalRecords": 1, "sEcho": 99, "iTotalDisplayRecords": 1}
Can anyone help me with this. Everything seems to be fine. but why cant i able to add a new?
and also here is the link that i posted the question in stackoverflow http://stackoverflow.com/questions/25386341/how-to-add-new-row-in-a-datatable