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

NirmalaSudhirNirmalaSudhir Posts: 1Questions: 1Answers: 0
edited August 2014 in Free community support

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

This discussion has been closed.