ypnos-web / cakephp-datatables

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

Draw callbacks #24

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi,

I'm sorry I seem to have some trouble understanding how to attach a callback to the draw event. I've tried numerous things none of which seem to work.

Could you maybe provide an example? If you have other things to do, don't mind this. I'm still relatively new to coding and I just seem not to get how to get this to work, as I'm sure it is just an amateur's mistake.

My code right now is:

<?php $options = [ 'ajax' => [ 'url' => $url // current controller, action, params ], 'language' => [ 'url' => 'http://cdn.datatables.net/plug-ins/1.10.12/i18n/Dutch.json' ], 'Callbacks' => [ 'drawCallback' => 'dt.render.drawn' ], 'data' => $data, 'deferLoading' => $recordsTotal, 'columns' => [ [ 'name' => 'Posts.id', 'data' => 'id', 'visible' => true, 'searchable' => false, ], [ 'title' => ('Name'), 'name' => 'Posts.name', 'data' => 'name', ], [ 'title' => ('Tags'), 'name' => 'Posts.tags', 'data' => 'tags' ], [ 'title' => ('Publish date'), 'name' => 'Posts.date', 'data' => 'date' ], [ 'title' => ('Removal date'), 'name' => 'Posts.end_date', 'data' => 'end_date' ], ], 'order' => [3, 'asc'], // order by date ]; ?>

<?= $this->DataTables->table('posts-table', $options, ['class' => 'table table-striped']); ?>

ypnos-web commented 7 years ago

It is explained in the wiki: https://github.com/ypnos-web/cakephp-datatables/wiki/Callback-functions You cannot pass a javascript function object as a string. That is why you need to use the callback wrapper, e.g. 'render' => $this->DataTables->callback('dt.render.date'),

ghost commented 7 years ago

Alright, thank you. Where, in the options array, would I bind an alert to for example draw.dt ?