Skip to content

[BUG]: change getColumns to be able to work with Relations with underscore DT #938

Open
@romanstingler

Description

@romanstingler

due to bugs

yajra/laravel-datatables#2324
yajra/laravel-datatables-html#123

due to code in
HasColumns.php

...
        foreach ($columns as $key => $value) {
            if (!is_a($value, Column::class)) {
                if (is_array($value)) {
                    $attributes = array_merge(
                        [
                            'name' => $value['name'] ?? $value['data'] ?? $key,
                            'data' => $value['data'] ?? $key,
                        ],
                        $this->setTitle($key, $value)
                    );
                } 
...

the default template doesn't work

protected function getColumns()
{
        return [
           'jobState.name'
        ];
}

the working solution is to change the returned array and the working function looks like

    protected function getColumns()
    {
        return [
            'jobState.name' => ['data' => 'job_state.name', 'name' => 'jobState.name'],
        ];
    }

so the key is used for the title due to this line
$this->setTitle($key, $value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions