mRender giving an initial error
mRender giving an initial error
leeguth
Posts: 19Questions: 1Answers: 0
I am using the mRender to display a count (not coming back in my ajax call) and a button (using a value in my data that I am not displaying). When i initially load the page, I get the following error: "DataTables warning (table id = 'example'): Requested unknown parameter '1' from the data source for row0."
After I get the error though, the page does display correctly. How do I get rid of the error?
Here is my ajax call:
success:function(data){
oTable = $('#example').dataTable( {
"bProcessing": true,
"aaData": data,
"aoColumns": [
{
"mData": null,
"sClass": "control center",
"sDefaultContent": ''
},
{ "mRender": function(data,type, row) {
return getProjectCount(row.prg_guid);
}
},
{ "mData": "prg_name" },
{ "mData": "market" },
{ "mData": "beta_date" },
{ "mData": "rtc_date" },
{ "mRender": function(data, type, row) {
if (row.prj_guid != ""){
return "Open in cPro";
} else
return "No cPro";
}
}
]
} );
}
I am hopefully using the mRender properly.....
After I get the error though, the page does display correctly. How do I get rid of the error?
Here is my ajax call:
success:function(data){
oTable = $('#example').dataTable( {
"bProcessing": true,
"aaData": data,
"aoColumns": [
{
"mData": null,
"sClass": "control center",
"sDefaultContent": ''
},
{ "mRender": function(data,type, row) {
return getProjectCount(row.prg_guid);
}
},
{ "mData": "prg_name" },
{ "mData": "market" },
{ "mData": "beta_date" },
{ "mData": "rtc_date" },
{ "mRender": function(data, type, row) {
if (row.prj_guid != ""){
return "Open in cPro";
} else
return "No cPro";
}
}
]
} );
}
I am hopefully using the mRender properly.....
This discussion has been closed.
Replies
Allan
Allan
for example: (I blanked on most of the url below because it was company specific and this is only a small portion of the code) The value of 'burl' is correct because i can take out the ajax call and output the value, just seems when i do the ajax call that it is causing the error.
{ "mData": null,
"mRender": function(data,display, row) {
var burl = "https://...../beta/"+row.prg_guid;
$.ajax({
url:burl,
success:function(data2){
if (data2 == "green"){
return "";
}
}
}
]
} );
}
} );
}
Would you have any suggestions of a different way to do this, if I can't have the ajax call in the mRender?
Yes, but remember what the first letter of Ajax stands for: _asynchronous_. mRender is executed synchronously, and expects the data back as such. But your Ajax is completing after that. You could make it Sjax, but that will _kill_ performance.
You'd be much better trying to get all the data you need into the data structure.
Allan
I've been wondering on my issue of needing to call a function (that requires an ajx call) to fill in a value....Could I give the cell a sName and a value of null. Then use a .each call on the success of the ajax call to loop through each table row and update the particular cell (column) with the value?
I saw the documentation for fnUpdate and wasn't sure if that could be what I could use. I couldn't tell by the example though if I could use it that way or exactly how I would go about it.
You documentation example shows the code below....and seems to allow updating a cell at a time.
$(document).ready(function() {
var oTable = $('#example').dataTable();
oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1 ); // Row
} );
Can I call the single cell example in conjunction with the each? If so, the two zeroes shown....would I need to change that to 'row' reference somehow? And can I reference the cell by the name I give it or do I need to provide a number there?
You might find it easier to understand using the new API in DataTables 1.10 - http://next.datatables.net/reference/api/cell().data() (I need to update the forum linking - you need to add the `()` at the end manually - sorry.
Allan