ypnos-web / cakephp-datatables

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

Uncaught ReferenceError: dt is not defined #59

Closed renjithjr closed 6 years ago

renjithjr commented 6 years ago

Notice (8): Undefined index: columns [ROOT/vendor/ypnos-web/cakephp-datatables/src/View/Helper/DataTablesHelper.php, line 101]

Warning (2): Invalid argument supplied for foreach() [ROOT/vendor/ypnos-web/cakephp-datatables/src/View/Helper/DataTablesHelper.php, line 101]

ypnos-web commented 6 years ago

Seems like you forgot to provide columns option as explained in the tutorial.

renjithjr commented 6 years ago

No i have provided columns option as explained in the tutorial.

$columns = [ [ 'field' => 'Customers.id', 'data' => 'id', 'searchable' => false, ],
[ 'title' => ('Title'), 'field' => 'Customers.name', 'data' => 'name' ], [ 'title' => ('Actions'), 'field' => 'Customers.id', 'data' => 'id' ], ];

ypnos-web commented 6 years ago

Please provide full code, this snippet does not show your call into DataTables helper.

renjithjr commented 6 years ago

### Controller

public function index() { $columns = [ [ 'field' => 'Customers.id', 'data' => 'id', 'searchable' => false, ],
[ 'title' => ('Title'), 'field' => 'Customers.name', 'data' => 'name' ], [ 'title' => ('Actions'), 'field' => 'Customers.id', 'data' => 'id' ], ];

    $data = $this->DataTables->find('Customers', 'all', ['conditions'=>[], 'order'=>'Customers.id desc'], $columns);

    $this->set('columns', $columns);
    $this->set('data', $data);
    $this->set('_serialize', array_merge($this->viewVars['_serialize'], ['data']));
}
ypnos-web commented 6 years ago

Please format your code in a readable manner, to be honest I consider it quite rude to dump the code like this when you are asking for help.

ypnos-web commented 6 years ago

Next time try ```php it is in the Github Markdown documentation.

ypnos-web commented 6 years ago

There is some other problems in your code, but I really don't see how you could get to this error message with the code you posted.

  1. use $columns passed from controller instead of re-defining
  2. selector argument to draw() is missing a '#'
  3. what's the document.ready event handler supposed to do?