File tree Expand file tree Collapse file tree 5 files changed +51
-33
lines changed Expand file tree Collapse file tree 5 files changed +51
-33
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
11
11
- Arabic translations
12
12
- Ability to add a link to make table rows clickable
13
13
- Added the ability to change the sort icons
14
+ - Ability to hide a column based on a condition or permanently
14
15
15
16
### Updated
16
17
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ class UsersTable extends TableComponent
48
48
return [
49
49
Column::make('ID')
50
50
->searchable()
51
- ->sortable(),
51
+ ->sortable()
52
+ ->hideIf(!auth()->user()->hasRole('admin')),
52
53
Column::make('Name')
53
54
->searchable()
54
55
->sortable(),
@@ -138,6 +139,16 @@ public function customAttribute() : self;
138
139
* This view will be used for the column, can still be used with sortable and searchable.
139
140
*/
140
141
public function view($view, $viewModelName = 'model') : self;
142
+
143
+ /**
144
+ * Hide this column permanently
145
+ */
146
+ public function hide() : self;
147
+
148
+ /**
149
+ * Hide this column based on a condition. i.e.: user has or doesn't have a role or permission
150
+ */
151
+ public function hideIf($condition) : self;
141
152
```
142
153
143
154
### Properties
Original file line number Diff line number Diff line change @@ -27,15 +27,17 @@ class="{{ $this->setTableRowClass($model) }}"
27
27
@endif
28
28
29
29
@foreach ($columns as $column )
30
- <td
31
- class =" {{ $this -> setTableDataClass ($column -> attribute , Arr:: get ($model -> toArray (), $column -> attribute )) } }"
32
- id =" {{ $this -> setTableDataId ($column -> attribute , Arr:: get ($model -> toArray (), $column -> attribute )) } }"
33
- @foreach ($this -> setTableDataAttributes ($column -> attribute , Arr:: get ($model -> toArray (), $column -> attribute )) as $key => $value )
34
- {{ $key } } =" {{ $value } }"
35
- @endforeach
36
- >
37
- @include (' laravel-livewire-tables::includes._column-data' )
38
- </td >
30
+ @if (! $column -> isHidden () )
31
+ <td
32
+ class =" {{ $this -> setTableDataClass ($column -> attribute , Arr:: get ($model -> toArray (), $column -> attribute )) } }"
33
+ id =" {{ $this -> setTableDataId ($column -> attribute , Arr:: get ($model -> toArray (), $column -> attribute )) } }"
34
+ @foreach ($this -> setTableDataAttributes ($column -> attribute , Arr:: get ($model -> toArray (), $column -> attribute )) as $key => $value )
35
+ {{ $key } } =" {{ $value } }"
36
+ @endforeach
37
+ >
38
+ @include (' laravel-livewire-tables::includes._column-data' )
39
+ </td >
40
+ @endif
39
41
@endforeach
40
42
41
43
@if ($checkbox && $checkboxLocation === ' right' )
Original file line number Diff line number Diff line change 3
3
@endif
4
4
5
5
@foreach ($columns as $column )
6
- <th
7
- class =" {{ $this -> setTableHeadClass ($column -> attribute ) } }"
8
- id =" {{ $this -> setTableHeadId ($column -> attribute ) } }"
9
- @foreach ($this -> setTableHeadAttributes ($column -> attribute ) as $key => $value )
10
- {{ $key } } =" {{ $value } }"
11
- @endforeach
12
- >
13
- @if ($column -> sortable )
14
- <span style =" cursor : pointer ;" wire:click =" sort('{{ $column -> attribute } } ')" >
15
- {{ $column -> text } }
6
+ @if (! $column -> isHidden () )
7
+ <th
8
+ class =" {{ $this -> setTableHeadClass ($column -> attribute ) } }"
9
+ id =" {{ $this -> setTableHeadId ($column -> attribute ) } }"
10
+ @foreach ($this -> setTableHeadAttributes ($column -> attribute ) as $key => $value )
11
+ {{ $key } } =" {{ $value } }"
12
+ @endforeach
13
+ >
14
+ @if ($column -> sortable )
15
+ <span style =" cursor : pointer ;" wire:click =" sort('{{ $column -> attribute } } ')" >
16
+ {{ $column -> text } }
16
17
17
- @if ($sortField !== $column -> attribute )
18
- <i class =" {{ $sortDefaultClass } }" ></i >
19
- @elseif ($sortDirection === ' asc' )
20
- <i class =" {{ $ascSortClass } }" ></i >
21
- @else
22
- <i class =" {{ $descSortClass } }" ></i >
23
- @endif
24
- </span >
25
- @else
26
- {{ $column -> text } }
27
- @endif
28
- </th >
18
+ @if ($sortField !== $column -> attribute )
19
+ <i class =" {{ $sortDefaultClass } }" ></i >
20
+ @elseif ($sortDirection === ' asc' )
21
+ <i class =" {{ $ascSortClass } }" ></i >
22
+ @else
23
+ <i class =" {{ $descSortClass } }" ></i >
24
+ @endif
25
+ </span >
26
+ @else
27
+ {{ $column -> text } }
28
+ @endif
29
+ </th >
30
+ @endif
29
31
@endforeach
30
32
31
33
@if ($checkbox && $checkboxLocation === ' right' )
Original file line number Diff line number Diff line change 3
3
namespace Rappasoft \LaravelLivewireTables \Views ;
4
4
5
5
use Illuminate \Support \Str ;
6
+ use Rappasoft \LaravelLivewireTables \Traits \CanBeHidden ;
6
7
use Rappasoft \LaravelLivewireTables \Traits \HasComponents ;
7
8
8
9
/**
9
10
* Class Column.
10
11
*/
11
12
class Column
12
13
{
13
- use HasComponents;
14
+ use CanBeHidden,
15
+ HasComponents;
14
16
15
17
/**
16
18
* @var
You can’t perform that action at this time.
0 commit comments