Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Necessary to re-set columns #4

Open
kuebel opened this issue Sep 14, 2021 · 0 comments
Open

Necessary to re-set columns #4

kuebel opened this issue Sep 14, 2021 · 0 comments

Comments

@kuebel
Copy link

kuebel commented Sep 14, 2021

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:

  1. 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

  1. 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);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant