fnUpdate a row (server-side data source)

fnUpdate a row (server-side data source)

ericpanorelericpanorel Posts: 7Questions: 0Answers: 0
edited February 2012 in DataTables 1.9
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]

Replies

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    fnUpdate is effectively useless when you are using server-side processing. DataTables knows nothing about your server environment, and so can't update the database (or whatever you happen to be using) when you call fnUpdate. If you are using server-side processing and want to modify the data, you need to modify the data source (i.e. the server) - so an update in this case would be to make an Ajax call to your update script, have it update the database as required and then call fnDraw on the table to load the new data.

    Allan
  • ericpanorelericpanorel Posts: 7Questions: 0Answers: 0
    Yeah, I thought about this too, but fnDraw would be an "expensive" call to the server as it loads the whole page again?
    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?
  • ericpanorelericpanorel Posts: 7Questions: 0Answers: 0
    fnDraw doesn't seem to refresh data from the server. Am I calling right function?
  • ericpanorelericpanorel Posts: 7Questions: 0Answers: 0
    It seems like it was caused by the pipelining code... When I removed it, fnDraw works again
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    If you are using pipeline then you need to invalidate the currently cached data by setting oCache.iCacheLower = -1.

    > 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
This discussion has been closed.