ypnos-web / cakephp-datatables

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

Suggestion about DataTablesHelper.php and add block name to table function #84

Open wash34000 opened 3 years ago

wash34000 commented 3 years ago

Hello,

Do you thinks that it will possible to add a params to table function (file DataTablesHelper.php) to select the block name where the code will be appear in the layout ?

    public function table(string $id = 'datatable', array $dtOptions = [], array $htmlOptions = [], string $blocName = '') : string
    {
        $htmlOptions = array_merge($htmlOptions,  [
            'id' => $id,
            'class' => 'dataTable ' . ($htmlOptions['class'] ?? ''),
        ]);
        $table = $this->Html->tag('table', '', $htmlOptions);

        $code = $this->draw("#{$id}", $dtOptions);

        if ($blockName != '') {
           return $table.$this->Html->scriptBlock($code, ['block' => $blockName]);
        } else {
           return $table.$this->Html->scriptBlock($code);
        }
    }
ypnos commented 3 years ago

I'm not so sure if that's worth the convolution of the interface, you can simply call Html->tag() and DatatablesHelper->draw() directly instead of using DatatablesHelper->table(), which is purely a method for convenience.