Switch state inside a data: null, render: function() gives Unknown parameter 'null'
Switch state inside a data: null, render: function() gives Unknown parameter 'null'

i have that message: DataTables warning: table id=example - Requested unknown parameter 'null' for row 107, column 26.
when i call for that data:
{
data: null, render: function ( data, type, row ) {
var eu_countries = [ "AL", "AD", "AM", "AT", "BY", "BE", "BA", "BG", "CH", "CY", "CZ", "DE",
"DK", "EE", "ES", "FO", "FI", "FR", "GB", "GE", "GI", "GR", "HU", "HR",
"IE", "IS", "IT", "LT", "LU", "LV", "MC", "MK", "MT", "NO", "NL", "PL",
"PT", "RO", "RU", "SE", "SI", "SK", "SM", "TR", "UA", "VA",
];
switch (true) {
case data.advertisers.nation === 'ES' && data.advertisers.money === '€':
return 'CPI ING PÑ';
break;
case data.advertisers.nation === 'ES' && data.advertisers.money === '$':
return 'CPI PÑ USD';
break;
case data.advertisers.nation !== 'ES' && (eu_countries.includes(data.advertisers.nation))==true && data.advertisers.money === '€':
return "CPI ING CE";
break;
case data.advertisers.nation !== 'ES' && (eu_countries.includes(data.advertisers.nation))==true && data.advertisers.money === '$':
return "CPI CEE USD";
break;
case (eu_countries.includes(data.advertisers.nation)) == false && data.advertisers.money=== '€':
return "CPI ING EX";
break;
case (eu_countries.includes(data.advertisers.nation)) == false && data.advertisers.money=== '$':
return "CPI EX USD";
break;
}
}
},
I think the problem is function is getting the NULL first, because the Switch statement need data to be render for returning a value.
Information is displayed correctly, buy all the time i enter the page the Null error message is displayed. How can i avoid that message from beeing displayed / solve that?
This question has an accepted answers - jump to answer
Answers
Not sure I fully understand your function but it I think nothing will be returned if one of the cases is not matched. That could be the problem with getting the "Null" error. I would try returning something appropriate (maybe just
data
) after the switch statement to see if that eliminates the error.Then you might need to see why the data for row 107 doesn't match one of your cases.
Kevin
My guess is that one of your case statements doesn't match the data in the row and thus the function is returning undefined.
Perhaps add
return '';
at the end of the function for such cases.Allan
You were right, there was 1 result that does not match. That's why it returned the null.
thanks