Skip to content

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

Description

@alanapplyby

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions