How to validate if {data: 1} exists?
How to validate if {data: 1} exists?
How can I validate if there is data in the json response?
example:
'ajax': {
'url':'serverside/show.materia.prima.php'
},
//"oSearch": {"sSearch": varsearch},
"columns": [
{ data: "cod_piku" },
{ data: 1 }
],
I need to be able to ask if it exists, because in ajax,
I'm sending data: 1 if it meets a condition,
if not, then I only send cod_piku.
and it is necessary to validate if data: 1 comes because otherwise I have an error Cannot read property 'style' of undefined TypeError: Cannot read property 'style' of undefined
This discussion has been closed.
Answers
Add
defaultContentto the column and you shouldn't get errors, like this:Kevin
It only works when there is data: "cod_piku" and data: 1, I don't know if I understand:
Example I have two th, if the condition is met both th are drawn.
but if it is not fulfilled, only one is drawn.
and it is the same as I need to validate in js Datatables.
if there is both data: cod_piku and data: 1
this would be the result:
"columns": [
{ data: "cod_piku" },
{ data: 1 }]
if only data exists: cod_piku
"columns": [
{ data: "cod_piku" }]
this doesn't work for me, I keep getting the same error:
{ data: 30, "defaultContent": "" }
I think you're going to need to parse the returned data within
ajax.dataSrc, and if that second element is missing, add it in. As DataTables is initialised with the two headers, it's going to expect to see two elements in that data set.Colin