ypnos-web / cakephp-datatables

CakePHP3 Plugin for DataTables plug-in for jQuery
MIT License
27 stars 24 forks source link

Changing name for variable $data, 'TypeError: c is undefined' 'TypeError: data is undefined' #22

Closed ranferi closed 7 years ago

ranferi commented 7 years ago

When I changed the name of $data, for example, $users and tried to load the next items from the table the browser's console throw me this errors TypeError: c is undefined (datatables.min.js) and TypeError: data is undefined (datatables.js debug). Changed back my code and it works. So should I left that variable as it is? Or there's a problem with my code? My code: `$users = $this->DataTables->find('Users', 'all', [ 'contain' => [], 'order' => ['id' => 'asc'] ]);

$this->set('users', $users); $this->set('_serialize', array_merge($this->viewVars['_serialize'], ['users']));`

and

<?php $options = [
'ajax' => [
 'url' => $this->Url->build()
],
'data' => $users,
'deferLoading' => $users->count(),
 'columns' => [
 [
 'title' => _('Id'),
 'name' => 'Users.id',
 'data' => 'id',
'searchable' => false,
],

// more code here
ranferi commented 7 years ago

Forget it. The answer is in here:

DataTables performs JSON requests and CakePHP's JSON view uses the _serialize view variable to determine which view variables to send back. The DataTables plugin sets a bunch of these, so it is crucial to append the data variable here. If your view variable is not called 'data', set DataTables ajax.dataSrc option.