ypnos-web / cakephp-datatables

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

Issue - Column ordering requested, but no column definitions provided #65

Closed inimist closed 6 years ago

inimist commented 6 years ago

Configured with the following code:

In Controller:

public function index()
{
    $data = $this->DataTables->find('Cases', 'all', [
        //'contain' => ['Departments'],
        'order' => ['id' => 'asc']
    ]);
    $this->set('data', $data);
    $this->set('_serialize', array_merge($this->viewVars['_serialize'], ['data']));
}

in index.ctp:

$options = [
    'ajax' => [
        'url' => $this->Url->build() // current controller, action, params
    ],
    'data' => $data,
    'deferLoading' => $data->count(), // https://datatables.net/reference/option/deferLoading
    'columns' => [
        [
            'data' => 'id',
            'visible' => true,
            'searchable' => false,
        ],
        [
            'title' => __('Case Number'),
            'data' => 'case_number'
        ],
        [
            'title' => __('Case name'),
            'data' => 'case_name'
        ],
        [
            'title' => __('Status'),
            'data' => 'status'
        ],
        [
            'title' => __('Created'),
            'data' => 'created'
        ],
        [
            'title' => __('Action'),
            'data' => 'created'
        ],
    ],
    'order' => [0, 'asc'], // order by id
];
echo $this->DataTables->table('users-table', $options, ['class' => 'table table-striped']);

The first screen is loaded just fine but when I use ordering or pagination it gives the following error:

{
    "message": "Column ordering requested, but no column definitions provided.",
    "url": "\/admin\/cases?draw=2\u0026amp;columns%5B0%5D%5Bdata%5D=id\u0026amp;columns%5B0%5D%5Bname%5D=\u0026amp;columns%5B0%5D%5Bsearchable%5D=false\u0026amp;columns%5B0%5D%5Borderable%5D=true\u0026amp;columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=\u0026amp;columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false\u0026amp;columns%5B1%5D%5Bdata%5D=case_number\u0026amp;columns%5B1%5D%5Bname%5D=\u0026amp;columns%5B1%5D%5Bsearchable%5D=true\u0026amp;columns%5B1%5D%5Borderable%5D=true\u0026amp;columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=\u0026amp;columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false\u0026amp;columns%5B2%5D%5Bdata%5D=case_name\u0026amp;columns%5B2%5D%5Bname%5D=\u0026amp;columns%5B2%5D%5Bsearchable%5D=true\u0026amp;columns%5B2%5D%5Borderable%5D=true\u0026amp;columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=\u0026amp;columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false\u0026amp;columns%5B3%5D%5Bdata%5D=status\u0026amp;columns%5B3%5D%5Bname%5D=\u0026amp;columns%5B3%5D%5Bsearchable%5D=true\u0026amp;columns%5B3%5D%5Borderable%5D=true\u0026amp;columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=\u0026amp;columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false\u0026amp;columns%5B4%5D%5Bdata%5D=created\u0026amp;columns%5B4%5D%5Bname%5D=\u0026amp;columns%5B4%5D%5Bsearchable%5D=true\u0026amp;columns%5B4%5D%5Borderable%5D=true\u0026amp;columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=\u0026amp;columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false\u0026amp;columns%5B5%5D%5Bdata%5D=created\u0026amp;columns%5B5%5D%5Bname%5D=\u0026amp;columns%5B5%5D%5Bsearchable%5D=true\u0026amp;columns%5B5%5D%5Borderable%5D=true\u0026amp;columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=\u0026amp;columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false\u0026amp;order%5B0%5D%5Bcolumn%5D=0\u0026amp;order%5B0%5D%5Bdir%5D=asc\u0026amp;start=10\u0026amp;length=10\u0026amp;search%5Bvalue%5D=\u0026amp;search%5Bregex%5D=false\u0026amp;_=1534836670252",
    "code": 500,
    "file": "C:\\wamp\\www\\connectsolutions\\vendor\\ypnos-web\\cakephp-datatables\\src\\Controller\\Component\\DataTablesComponent.php",
    "line": 108
}

Any idea?

inimist commented 6 years ago

Sorry it was my mistake. I did not created and pass $columns variable in my index method in the controller. All good now!