ypnos-web / cakephp-datatables

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

Callback function seem to only work if params are passed - possible bug? #87

Open alanapplyby opened 3 years ago

alanapplyby commented 3 years ago

Isn't there a small bug in the construct callback function of the plugin:

public function __construct(string $name, array $args = [])
    {
        if (empty($args)) {
            $code = $name;
        } else {
            $code = 'function () { ';
            foreach ($args as $a) {
                $arg = json_encode($a);
                $code .= "Array.prototype.push.call(arguments, {$arg});";
            }
            $code .= "return {$name}.apply(this, arguments); }";
        }

        $this->setHash($code);
    }

Seems that this forces any callback function to use parameters, otherwise the construct just returns the hash of $name.

In my example I have a callback function that doesn't require any paranmters:

dt.render.foo = function (data, type, full, meta) {
        ....
        return foobar;
    }

$columns[7]['render'] = $this->DataTables->callback('foo');

This will not call the callback function so I have to do something like this to force it to work:

$columns[7]['render'] = $this->DataTables->callback('foo', [false]);

Or did I mis-understand something about how this should work?

Thanks.