How to hide column based on the conditon #1286
Replies: 2 comments
-
Based on the information provided in the knowledge sources, I can help you with hiding a column based on a condition in Backpack. The approach you're trying is close, but there's a more appropriate way to achieve this in Backpack. Here's how you can do it: $this->crud->addColumn([
'label' => 'Account Number',
'name' => 'acct_no',
'priority' => 1,
'visibleInTable' => function ($entry) {
return $entry->status === 'completed';
}
]); This code should work correctly in Backpack 5.6. The However, there are a couple of things to note:
For example, if you want to hide the column in all contexts based on the same condition, you could do: $this->crud->addColumn([
'label' => 'Account Number',
'name' => 'acct_no',
'priority' => 1,
'visibleInTable' => function ($entry) {
return $entry->status === 'completed';
},
'visibleInModal' => function ($entry) {
return $entry->status === 'completed';
},
'visibleInExport' => function ($entry) {
return $entry->status === 'completed';
},
'visibleInShow' => function ($entry) {
return $entry->status === 'completed';
}
]); This approach should effectively hide the 'acct_no' column when the status is not 'completed' in all relevant contexts. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Columns|Choose Where Columns are Visible |
Beta Was this translation helpful? Give feedback.
-
Hey @blessen131
To hide the content of this particular column per entry basis on the table, you can use closure column: [
'name' => 'acct_no',
'type' => 'closure',
'function' => function($entry) {
return $entry->status === 'completed'? $entry-> acct_no : " ";
}
] |
Beta Was this translation helpful? Give feedback.
-
I was trying to show column
name
only if the status iscompleted
otherwise hide the name column.visibleInTable
is not working!$this->crud->addColumn([
'label' => 'Name',
'name' => 'name',
'priority' => 1,
'visibleInTable' => function($entry) {
return $entry->status === 'completed';
}
]);
"backpack/crud": "^5.6"
Beta Was this translation helpful? Give feedback.
All reactions