Error DataTables warning: Requested unknown parameter calling a function inside render
Error DataTables warning: Requested unknown parameter calling a function inside render
Hello everyone,
i have a problem calling a function inside the render function.
If i use the the code below all is working fine, but if i put the code inside a function and i call that function from within the render, i get the DataTables warning: Requested unknown parameter 'userId' for row 0, column 10. For more information about this error, please see http://datatables.net/tn/4
{ "data": "userInfo", "name": "userInfo", "render": function ( data, type, row ) {
if (row.userId === 'undefined' || row.userId == null || row.userId == "") {
return "-";
} else if (row.name != null && row.name != "" && row.surname != null && row.surname!= "") {
return row.userId + ' ' + row.name + ' ' + row.surname;
} else {
return row.userId;
}
}
if i call a function inside the render, i get the error above
{ "data": "userInfo", "name": "userInfo", "render": function ( data, type, row ) {
return formatUserInfo(row.userId, row.name, row.surname);
}
I don't check for the row validity in the second case and probably some parameters are resulting empy or null.
Any suggestion to avoid this problem?
Answers
In some of your rows "row.userId" seems to be undefined. I tested with a non existing field called "bla".
This code always gave me the data tables error:
This code worked because I included "typeof". I have not seen your "undefined" syntax before to be honest. Seems to be causing issues.
This also worked:
I would check your syntax and if that isn't the cause you should post a test case. Or, as a first step, the exact code of the function you are calling.
Thank you for the reply.
The code in the first case works well.
The code in the second case doesn't work.
I call a function in the second case. This doesn't work, giving me the error described above.
The function formatUserInfo does exactly what you see in the first case.
Have you fixed the syntax error? Or is your field really a string with value "undefined"?
To be clear: There is absolutely no difference between doing the rendering in a called function or not. I do this hundreds of times and it always works So there has to be a slight deviation in your code. But I see you don't want to post your exact code which is ok for me. But then I am unable to help you further.
Please post a test case as per the forum rules.
@rf1234
you're right about the 'undefined' syntax, btw.
The correct syntax is without the '', that i alredy tested before.
I used typeof also, but as said previously, the problem is not in the first case, but in the second case.
Again: Since you are not posting your code I can't help you. Thank you for your understanding.
this is the function code:
We will need to see the problem to help debug. Please post a test case with an example of the data causing the issues and the
render
function you are trying to use.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I tested your function. It worked fine with an undefined userID, a userID which is null and a userID which is an empty string. Couldn't find any issues.
Unfortunately i'm not authorized to post any other part of source or data related to this project. I will continue to use the first code as in the first case.
Thank you anyway for the help.
A test case only requires the code you've already posted here and a sample (doesn't have to be the same) of the data that is causing the problem. Start with thie:
http://live.datatables.net/
Kevin