Closed Mehrdad-Dadkhah closed 11 years ago
Check the response of the request that datatables is doing to cake, you can check it with firebug, you must getting html instead of json
Hey @luisillo26 ..I have the same error, where do i check that in cake? Thanks..
You have to check the response of the datatables request.
If you use Firebug or Chrome Inspector, you can view it in the network tab.
If Cake is triggering errors (only if you have your debug config higher than 0), surely cake's response is an HTML with the description of the error so you will know what to do to fix it.
Thanks.. i got my error Array to string conversion [CORE/Cake/Model/Datasource/DboSource.php, line 461] Database Error
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'customSearch' at line 1
Sweet!! i'm glad you found it.
Saludos!!
Thanks for helping out @luisillo26
@joshdcid Were you able to get it all working?
Yes! Thanks.. i been looking for a way to have inside a row in datatables edit, view and delete.. how you came across with that problem?
But everything else is working.. thanks..
In your columns, setup a non-table column (either by 'Actions' => null
or 'actions' => array(..some options.., 'useField' => false)
.
Then in your view:
foreach($dtResults as $result) {
$this->dtResponse['aaData'][] = array(
$result['Model']['field_a'],
$this->Html->link('View', array('action' => 'view', $result['Model']['id'])) . .. the rest of your links for the actions
);
}
Hey.. i have the same problem again.. "DataTables warning (table id = 'DataTables_Table_0'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error."
I don't have any problem in the console or in the network area, and the last time it work 'cause i generate the JSON my self, but now i'm trying to use your plugin and i can't make it work.. I simplify everything to try and find my error..
Thanks in advance.. sorry for all the trouble..
Look at the network tab after the datatable makes a request for data. It may be returning HTML because there is an error happening. If it is, what does the error say?
I guess this one has to be JSON.. but i got no error..
Yea see how it has text/html, so there is an issue. Look at the contents of that request.
Well i don't see any error on my code, do i have to put some echo json_encode( ) to something? or do i need to have a separte function only for paginate?
*In my View/Users/datatable.ctp echo $this->DataTable->render();
In my View/Users/datatable/datatable.ctp foreach($dtResults as $result) { $this->dtResponse['aaData'][] = array( $result['User']['id'], $result['User']['username'], $result['User']['email'], 'actions', ); }
In the Network tab, click on the request made by datables and then click Response. There you should see what was returned. It's going to be HTML, but most likely there will be an error message somewhere in it.
Mmm nop.. here is the response.. from the Network tab.. http://bin.cakephp.org/view/1486975118 And in the image is the preview from the Network tab. Jajajaja sorry to bother you so much..
In your controller's action add: $this->DataTable->settings['trigger'] = 'datatable';
By default, datatable component is set to handle requests only when the action is index
, so you have to let it know that its the datatable
action you want it to automatically handle as a datatable request. It can also be an array of multiple actions, or *
for all actions.
Hello.. i change everything (Action in the controller, the view and in the datatable carpet) to index and i got an 500 Internal Server Error... and it says:
DateTableComponent: Model not specified for request.
Error: An Internal Error Has Occurred.
Stack Trace
[internal function] → DataTableComponent->beforeRender(UsersController) CORE/Cake/Utility/ObjectCollection.php line 130 → call_user_func_array(array, array) [internal function] → ObjectCollection->trigger(CakeEvent) CORE/Cake/Event/CakeEventManager.php line 246 → call_user_func(array, CakeEvent) CORE/Cake/Controller/Controller.php line 922 → CakeEventManager->dispatch(CakeEvent) CORE/Cake/Routing/Dispatcher.php line 193 → Controller->render() CORE/Cake/Routing/Dispatcher.php line 161 → Dispatcher->_invoke(UsersController, CakeRequest, CakeResponse) APP/webroot/index.php line 100 → Dispatcher->dispatch(CakeRequest, CakeResponse)
It has to do with something I (think) I fixed in the bug-fixes
branch.
So change your view to $this->DataTable->render('User', array(), array('sAjaxSource' => array());
That was it!!!... Thanks! it work...
No problem :)
I do have it fixed in bug-fixes
branch. I can't remember why I haven't merged it (there are other changes along with it).
You can grab the latest master
branch. I added the fix just for this right now. So you can just use $this->DataTable->render()
without the extra params.
Great i will clone it!.. Thanks..
I want to add a delete link to 'Category', which will only show up, when there is no 'Items' of this Category. How to add link depend for if statement ?
Create a variable for your row with the values you want in each column, $row = array($result['Category']['name'], etc...)
Then check your condition: if (...) { $row[column_index_here] = 'your delete link'; }
And append the row to response $this->dtResponse['aaData'][] = $row;
It works! Thanks
hi thansk for plugin ...
but i have this js error: DataTables warning (table id = 'DataTables_Table_0'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.