fnUpdate a row (server-side data source)
fnUpdate a row (server-side data source)
ericpanorel
Posts: 7Questions: 0Answers: 0
I am getting an error saying: [quote]DataTables warning (table id = 'table-content'): Requested unknown parameter 'partid' from the data source for row 0 [/quote]
I am thinking I am not properly using fnUpdate function. Any thoughts?
Here is my code:
[code]
$(document).ready(function () {
var oTable = $('#table-content').dataTable({ "iDisplayLength": 25,
"sPaginationType": "full_numbers",
"bServerSide": true,
"bLengthChange": false, // don't show dropdown for #items per page
"sAjaxSource": '@Url.Action("ListTable")',
"fnServerData": fnDataTablesPipeline,
"fnDrawCallback": function () {
$('.EditLink').on("click", function () {
var id = $(this).attr("id");
var rowid = "#" + id;
var aPos = oTable.fnGetPosition(this.parentNode); // gets the row node?
$("#NoteDialog").html("")
.load('@Url.Action("EditRecipe")/' + id, function () {
$("#NoteDialog").dialog({
title: 'Edit Recipe',
autoOpen: true, width: 500, height: 400, modal: true,
resizable: true,
buttons: {
"Save": function () {
$.post('@Url.Action("Save")',
$("#EditForm").serialize(),
function (data) {
if (data.Message) {
showError(data.Message);
} else {
$("#NoteDialog").dialog("close");
// $(rowid).load('@Url.Action("ListRow")/' + id); // old trick, load a partial view from the server
oTable.fnUpdate(data.Results, aPos[0], aPos[1], false, true); // does not work, data is in data.Results JSON object
}
});
},
Cancel: function () { $(this).dialog("close"); }
}
}); // End adding dialog
});
}); //edit
},
"bProcessing": true, // progress indicator
"aoColumnDefs": [
{ "sName": "partid",
"aTargets": [0],
"mDataProp": "partid",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
var id = oObj.aData["partid"];
var s = 'Edit |';
s += 'Details |';
s += 'Delete |'; ;
return s;
}
},
{"sName": "PartNumber", "aTargets": [1], "mDataProp": "PartNumber" },
{ "sName": "Zone1", "aTargets": [2], "mDataProp": "Zone1" },
{ "sName": "Notes", "aTargets": [3], "mDataProp": "Notes" }
]
}); // dataTable
});
[/code]
I am thinking I am not properly using fnUpdate function. Any thoughts?
Here is my code:
[code]
$(document).ready(function () {
var oTable = $('#table-content').dataTable({ "iDisplayLength": 25,
"sPaginationType": "full_numbers",
"bServerSide": true,
"bLengthChange": false, // don't show dropdown for #items per page
"sAjaxSource": '@Url.Action("ListTable")',
"fnServerData": fnDataTablesPipeline,
"fnDrawCallback": function () {
$('.EditLink').on("click", function () {
var id = $(this).attr("id");
var rowid = "#" + id;
var aPos = oTable.fnGetPosition(this.parentNode); // gets the row node?
$("#NoteDialog").html("")
.load('@Url.Action("EditRecipe")/' + id, function () {
$("#NoteDialog").dialog({
title: 'Edit Recipe',
autoOpen: true, width: 500, height: 400, modal: true,
resizable: true,
buttons: {
"Save": function () {
$.post('@Url.Action("Save")',
$("#EditForm").serialize(),
function (data) {
if (data.Message) {
showError(data.Message);
} else {
$("#NoteDialog").dialog("close");
// $(rowid).load('@Url.Action("ListRow")/' + id); // old trick, load a partial view from the server
oTable.fnUpdate(data.Results, aPos[0], aPos[1], false, true); // does not work, data is in data.Results JSON object
}
});
},
Cancel: function () { $(this).dialog("close"); }
}
}); // End adding dialog
});
}); //edit
},
"bProcessing": true, // progress indicator
"aoColumnDefs": [
{ "sName": "partid",
"aTargets": [0],
"mDataProp": "partid",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
var id = oObj.aData["partid"];
var s = 'Edit |';
s += 'Details |';
s += 'Delete |'; ;
return s;
}
},
{"sName": "PartNumber", "aTargets": [1], "mDataProp": "PartNumber" },
{ "sName": "Zone1", "aTargets": [2], "mDataProp": "Zone1" },
{ "sName": "Notes", "aTargets": [3], "mDataProp": "Notes" }
]
}); // dataTable
});
[/code]
This discussion has been closed.
Replies
Allan
And my "trick" to perform a "load" targeting on the row won't work either because datatables would loose it's tracking capabilities on this row?
> Yeah, I thought about this too, but fnDraw would be an "expensive" call to the server as it loads the whole page again?
That is correct yes - because the data has changed state, and the data is held only at the server-side, the table view must be refreshed. The alternative is to use DOM methods to update the table without telling DataTables - but you need to be certain that nothing else has changed in the data source from the server or the two would be out of sync.
Allan