Sweta Vora
Sweta Vora

Reputation: 11

column visibility: how to make few columns hidden by default in list view

I have displayed few column data in view using setColumns method like this:

$this->crud->setColumns([

                    (['name'=>'expire_date','lable'=>'Expire Date']),
                    (['name'=>'username','lable'=>'User']),
                    (['name'=>'prize_id','lable'=>'Prize']), /* New Column(must be hidden by default) */
                    (['name'=>'gifted_from','lable'=>'Gifted From'])  /* New Column(must be hidden by default) */
]);

What I expected to happen: now in the same list I want to add few more columns to be shown in list view. But by default this columns should be hidden in list view and what I expect that new added hidden columns (in the above list) i can make visible through column visibility options provided through $this->crud->enableExportButtons();

Is there any way to do this in laravel backpack?

Upvotes: 1

Views: 2020

Answers (2)

Sergei Krivosheenko
Sergei Krivosheenko

Reputation: 1366

It's a bit later but you can do 'visibleInTable' => false for a column you want to hide by default. You'll be able to make it visible in column visibility options.

For example:

[
    'name' => 'email',
    'label' => "Username",
    'visibleInTable' => false,
],

Upvotes: 0

user320487
user320487

Reputation:

You would add the fields you want hidden to the hidden property on the model:

/** 
  * The attributes that should be hidden for arrays.
  * 
  * @var array
  */
 protected $hidden = ['attribute'];

Then you can temporarily make fields visible by calling the makeVisible method:

$user->makeVisible('attribute')

See the docs on Serialization

Upvotes: 2

Related Questions