-
Notifications
You must be signed in to change notification settings - Fork 24
Troubleshooting
Typically it is most helpful to open your browser's debugging view, e.g. by pressing F12 in Chrome. Have a look at the Console where Javascript errors are displayed. They often tell you what the problem is.
The error occurs when $data
is JSON-encoded to be sent to the client in JSON format. Internally, this calls jsonSerialize()
on the Query object (which would then use toArray()
).
So this is the point when the query is executed and data is read. Pretty much always this is caused by a problem in my model. The most prominent cause for this error is a faulty SQL statement.
Unfortunately it is quite cumbersome to debug such a problem as the error message hides the real problem. You can try to do this in your view instead/before displaying the table:
debug($data->toArray());
This will explicitely execute the query. So the error should occur at this line and you should get a message describing the real problem. Obviously this can also be helpful:
debug($data);
It will show you the Query object, including the SQL statement.
From a bug report:
In my datatable I'm showing user data and the organization name but i have an error if a user is not linked to an organization.
In general, DataTables ignores missing data and just renders an empty cell. However, for security reasons (escaping) our plugin by default uses the $.fn.dataTable.render.text
renderer, which is not as forgiving.
A simple solution may be a dt.render.optional
renderer like this:
dt.render.optional = function (data, type, full, meta)
{
if (type != 'display')
return data;
return (typeof(data) === 'undefined' ? '' : dt.h(data)); // escapes HTML
}