proper way to deal with null data returned in server-side search processing
proper way to deal with null data returned in server-side search processing
Sometimes in MS SQL, I can't (or don't want to) send back a properly-formatted string, such as {"data":[]}
, when there is no data to return. Sometimes, if I do, I might send this {"data":null}
or this []
. DT will recognize that, and say, "No matching records found".
So, if I don't send anything back, is there some way inside of DT for me to tell it, "Hey, there's no records" if the structure is missing?
OR, does DT always expect some sort of structure, even when there are no records? (Some of the SQL queries are really hard to do)
This question has accepted answers - jump to:
Answers
Not sure if this is answering your question but if your JSON response doesn't always have all the columns you can use
defaultContent
to set a default for the missing data objects.Kevin
I was thinking something like that, but for when the entire data array was not returned. I recently send back
{"draw":1,"recordsTotal":137921,"recordsFiltered":null}
, and my webapp crashed. ("data":[]
was missing)Long story short, in retrospect, it's probably just better for me to always send back the expected structure
Yes, you will want something like this:
Kevin
Yup - DataTables always expects
data
to be an array - no exceptions . I've actually committed a change to the2
branch to handlenull
there, but v2 is a good long way for release....Allan