cakephp-datatables icon indicating copy to clipboard operation
cakephp-datatables copied to clipboard

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

Open wash34000 opened this issue 4 years ago • 1 comments

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);
        }
    }

wash34000 avatar May 31 '21 13:05 wash34000

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.

ypnos avatar May 31 '21 20:05 ypnos