Skip to content

Adding extra ajax parameters

shuadoc edited this page Feb 26, 2020 · 1 revision

Configuring javascript to send extra parameters in request

You'll need to use a custom Callback-functions to send javascript from PHP:

$options = [
    'ajax' => [
        'url'  => $this->Url->build('...'),
        'data' => $this->DataTables->callback("function(d) {
            d.customParameter = $('#myElement').val();
        }"),
    ],
    ....

(above code would be in a view)

Configuring controller to utilize extra parameters:

You can append additional where clauses to the end of the find result, and then will need to re-calculate the result count:

$data = $this->DataTables->find('table', 'all', [], $columns);
$data->where(['table.column' => $this->request->getQuery()['customParameter']]);

//Re-calculate count to display correct number of pages:
$this->viewVars['recordsFiltered'] = $data->count();