Crud: addColumn and setColumnDetails

Created on 29 Jan 2017  路  7Comments  路  Source: Laravel-Backpack/CRUD

Hi, i don't know if this is a issue.
I try to use addColumn to add 1-1 relationship in table's column but doesn't works.
Using setColumnDetails all works fine.
At this point i try to use addColumn for render database column with other column type but this works only if the original column is present. If i try to use removColumn to remove original column nothing is visible.
If i don't use removColumn so the column it's duplicated
thx for response

question

All 7 comments

Can you please show us some code ? Thanks

This is part of ClienteCrudController

 // ------ CRUD COLUMNS
        $this->crud->addColumn(
            [ 'name' => 'id_commerciale', // The db column name
'label' => "Featured", // Table column heading
'type' => 'check'
]
        ); 
        $this->crud->removeColumns(['id_sindaco', 'abitanti','telefono','note','cap','id_tipo_anomalia_cliente','id_commerciale','id_cliente_old']); // remove an array of columns from the stack
        $this->crud->setColumnDetails('id_tipo_cliente', ['label' => "Tipo Cliente", // Table column heading
   'type' => "select",
   'name' => 'id_tipo_cliente', // the column that contains the ID of that connected entity;
   'entity' => 'tipo_cliente', // the method that defines the relationship in your Model
   'attribute' => "descrizione", // foreign key attribute that is shown to user
   'model' => "App\Models\TipoCliente"]); // adjusts the properties of the passed in column (by name)
        // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']);

If i add the id_commerciale column in removeColumn Array nothingh s visible. If i dont add the column booth are visible.
I dont understand well the use oh removeColumn addColumn and setColumnDetail

Mate, look can you please make it more tidy because I can't understand anything, even if i can't see the problem in the code for relationship 1-1 use select2 as field type.

$this->crud->addColumn([  'name' => 'id_commerciale', 'label' => "Featured", 'type' => 'check']);
$this->crud->removeColumns(['id_sindaco',abitanti','telefono',
'note','cap','id_tipo_anomalia_cliente','id_commerciale','id_cliente_old']);

$this->crud->setColumnDetails('id_tipo_cliente', ['label' => "Tipo Cliente",  'type' => "select", 'name' => id_tipo_cliente',  'entity' => 'tipo_cliente',  'attribute' => "descrizione",  'model' =>App\Models\TipoCliente"]); 

In this code the column id_commerciale is not visible in datatable because is into the removeColumn array.
But if i remove from this array is visible twice: one for real column and one for addColumn method.
Maybe i dont understand the use of addColumn and setColumnDetails method

So this works:

$this->crud->setColumnDetails('id_tipo_cliente', ['label' => "Tipo Cliente",  'type' => "select", 'name' => 'id_tipo_cliente',  'entity' => 'tipo_cliente',  'attribute' => "descrizione",  'model' => App\Models\TipoCliente]); 

but this doesn't (after you remove the column, of course)?

$this->crud->addColumn(['label' => "Tipo Cliente",  'type' => "select", 'name' => 'id_tipo_cliente',  'entity' => 'tipo_cliente',  'attribute' => "descrizione",  'model' => App\Models\TipoCliente]); 

The second doesnt works if i add column in removeColumn array. But if i add column in addColumn array without remove column before the column is visible twice.
I believe the correct process it's

  1. Add column in removeColumn array
  2. Add column in Addcolumn array with code i wrote

Exactly! :-)

Was this page helpful?
0 / 5 - 0 ratings