I have a HTML table that I fill with data from an AJAX jQuery call.This table uses the jQuery plugin - datatables for paging, sorting and so on.
The jQuery call gets cal
you can use DataTables function fnClearTable and fnAddData like this
$("#Dropdownlist").on("change", function () {
$.ajax({
type: "POST",
url: "@Url.Action("Action", "Controller")",
//contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var oTable = $('#table').dataTable();//get the DataTable
oTable.fnClearTable();//clear the DataTable
$.each(data, function (key, item) {
oTable.fnAddData(["appending ","data","here"]);//add new row
//each element in the array is a td
});
/*no need to destroy and create new DataTable
$('#table').dataTable().fnDestroy();
$('#table').dataTable({
"aoColumns": [
{ "bSortable": false },
null, null, null, null, null
]
});
*/
}
})
});