I am populating rows into table body by using jQuery append function this works fine, but when I try to search any data from table then the table gets cleared.
Here is my code.
for (i = 0; i < mapping.length; i++) {
var tr = $('<tr>' + '<td>' + ' <input type="checkbox" '
+ ' onchange="selectItem(this);" '
+ (mapping[i]['selected'] == true ? "checked" : "")
+ ' data-el_id="' + mapping[i]['id'] + '">'
+ ' </td>' + ' <td>' + mapping[i]['name'] + ' </td>'
+ ' <td>' + mapping[i]['itemName'] + ' </td>' + ' <td>'
+ mapping[i]['url'] + ' </td>' + ' </tr>');
$("#tableBody").append(tr);
}
You need to go through the dataTables API in order to insert rows. I guess your data items looks like this :
Then, if you initialise your table like this :
You can insert all the rows in a loop :
small demo -> http://jsfiddle.net/fu0r4oba/