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

Necessary to re-set columns #4

Description

@kuebel

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

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions