How to refresh table after adding or removing a row from server
How to refresh table after adding or removing a row from server
SnigRO
Posts: 1Questions: 0Answers: 0
Hi all,
What am I do wrong?
I add or delete a row with javascript, then I want to refresh the table.
I tried to several methods, but I could not make it.
What am I missing?
refreshDT($("#myTable"));
[code]
function refreshDT(d) {
var dataTable = d.dataTable();
dataTable.fnDraw();
}
[/code]
OR I imported fnReloadAjax js
[code]
function refreshDT(d) {
var dataTable = d.dataTable();
var oSettings = dataTable.fnSettings();
d.dataTableExt.oApi.fnReloadAjax(oSettings);
}
[/code]
OR
[code]
function refreshDT(d) {
var dataTable = d.dataTable();
dataTable.fnClearTable(this);
var i=0;
$.getJSON('@Url.Action("GetAssetJSON", "Asset")', { get_param: 'value' }, function (data) {
$.each(data, function (index, json) {
dataTable.oApi._fnAddData(oSettings, json[i++]);
});
});
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
dataTable.fnDraw();
}
[/code]
Here is my table definition:
[code]
var oTable = $('#myTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bAutoWidth": true,
"bProcessing": true,
"iDisplayLength": 20,
"sAjaxSource": '@Url.Action("GetAssetJSON", "Asset")',
"aaSorting": [[0, "desc"]],
"aoColumns": [
{ "sClass": "right", "sType": "numeric" },
null,
null,
null,
null,
null,
{ "sType": "datetime_tr" },
null,
{ "bSortable": false },
{ "bSortable": false }
],
"sDom": 'Tfrtlip<"clear">'
});
[/code]
What am I do wrong?
I add or delete a row with javascript, then I want to refresh the table.
I tried to several methods, but I could not make it.
What am I missing?
refreshDT($("#myTable"));
[code]
function refreshDT(d) {
var dataTable = d.dataTable();
dataTable.fnDraw();
}
[/code]
OR I imported fnReloadAjax js
[code]
function refreshDT(d) {
var dataTable = d.dataTable();
var oSettings = dataTable.fnSettings();
d.dataTableExt.oApi.fnReloadAjax(oSettings);
}
[/code]
OR
[code]
function refreshDT(d) {
var dataTable = d.dataTable();
dataTable.fnClearTable(this);
var i=0;
$.getJSON('@Url.Action("GetAssetJSON", "Asset")', { get_param: 'value' }, function (data) {
$.each(data, function (index, json) {
dataTable.oApi._fnAddData(oSettings, json[i++]);
});
});
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
dataTable.fnDraw();
}
[/code]
Here is my table definition:
[code]
var oTable = $('#myTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bAutoWidth": true,
"bProcessing": true,
"iDisplayLength": 20,
"sAjaxSource": '@Url.Action("GetAssetJSON", "Asset")',
"aaSorting": [[0, "desc"]],
"aoColumns": [
{ "sClass": "right", "sType": "numeric" },
null,
null,
null,
null,
null,
{ "sType": "datetime_tr" },
null,
{ "bSortable": false },
{ "bSortable": false }
],
"sDom": 'Tfrtlip<"clear">'
});
[/code]
This discussion has been closed.