This repository was archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
This repository was archived by the owner on Oct 31, 2023. It is now read-only.
Necessary to re-set columns #4
Copy link
Copy link
Open
Description
Hi!
Creating a DataTables object like this
/**
* @param \DataTables\Table\ConfigBundle $configBundle
*/
public function config(ConfigBundle $configBundle): void {
$configBundle->Columns->addDatabaseColumn('Machines.name');
$configBundle->Columns->addDatabaseColumn('Machines.status');
$configBundle->Columns->addDatabaseColumn('Machinetypes.name');
$configBundle->Columns->addDatabaseColumn('Customers.name');
}
generates two errors for me:
- the "columns" part in the JSON containes the default columns of my Machines object - which has 7 columns - and thus the ajax data request runs into a warning and an errror:
Undefined offset: 4 [ROOT\vendor\wsssoftware\cakephp-datatables\src\Table\Columns.php, line 214]
Return value of DataTables\Table\Columns::getColumnByIndex() must be an instance of DataTables\Table\Column, null returned
I guess ->addDatabaseColumn does not change the config, just the Columns object
- the Customers is a INNER JOIN table to Machines, but there is some error in the query builder and it complains that Customers is not associated with Machines (which it is).
My workaround (and working) solution is a manual contain and a call to setColumns:
/**
* @param \DataTables\Table\ConfigBundle $configBundle
*/
public function config(ConfigBundle $configBundle): void {
$configBundle->Query->contain(['Customers']);
$configBundle->Columns->deleteAllColumns();
$configBundle->Columns->addDatabaseColumn('Machines.name');
$configBundle->Columns->addDatabaseColumn('Machines.status');
$configBundle->Columns->addDatabaseColumn('Machinetypes.name');
$configBundle->Columns->addDatabaseColumn('Customers.name');
$configBundle->Options->setColumns($configBundle->Columns);
}
Metadata
Metadata
Assignees
Labels
No labels