"render" function - "data" always undefined
"render" function - "data" always undefined

My server-side processing was working fine, and I was using the "render" function to output most of my columns, with the rest just defining "data" and "name". Suddenly it stopped working and I received ajax errors, and "data" in the render function was always "undefined". I wish I could tell you what change I made that caused this, but I couldn't figure it out. Here's where it gets weird...
In the "rowCallback" function, which has params "row" and "data", I can view these values in the console, and they're correct. If I use console to output "data" and "row" in the "columns" definition, "data" is "undefined", and "row" has the data in it, rather than the HTML row. To get around this issue for the moment, I've changed to using "row" with dot notation to access the data for that cell, like this:
{
data: "LeadFullName",
name: "co",
render: function (data, type, row) { // "data" is undefined here, "row" looks like it contains "data"
if (row)
return <div class="w100">${row.leadFullName}</div>
;
else
return null;
}
}
And THIS works, but I can't figure out why "data" suddenly started coming back "undefined", and why "row" now has "data" in it rather than HTML. I added a "success" callback to inspect exactly what I was getting back from the server, and it looks exactly like what I expect - variable values for "draw", "recordsTotal", "recordsFiltered", and "data", which is an array of the values. This is very strange, and I'm worried something is going wrong, even though it's currently working by using "row" instead of "data".
Answers
If you are getting an Ajax Error then there is something wrong with the response from the server. The error provides a troubleshooting link:
https://datatables.net/manual/tech-notes/7
The first steps are to follow the link's troubleshooting steps. Likely you are getting an error status code from the server which will require looking at the server logs to find out why its responding with the error.
Kevin
The response from the server is fine. Server response is 200, and the response passes JSON validation. The problem is that, when the render function rolls, "data" is undefined. When I output "data" to the console in the rowCallback function, it's exactly as I expect. When the "render" function of the columns collection runs, it's undefined, while "row" seems to have the "data" assigned to it.
I output the entire response in the "success" callback, and verified it for valid JSON and that "data" held the collection of data to render in table rows.
Guess I misunderstood and thought you mentioned getting an ajax error. You have
data: "LeadFullName",
but are returning<div class="w100">${row.leadFullName}</div>;
. You have a capitalL
indata: "LeadFullName",
but not inrow.leadFullName
. It case sensitive. I'm surprised you aren't getting theRequested unknown parameter
error regarding theLeadFullName
.If this doesn't help then we will need to see a link to your page or a test case replicating the issue. This way we can see your full config and the response data.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@Wilshire Hi I am facing the same issue, data is undefined and row has data in it. How do i get the data in 'data' variable?
@karthikaTL Please see my last comment on how to get help with this issue:
Kevin
@kthorngren Thanks for your help. It worked!