|
| 1 | +--- |
| 2 | +title: Icon Columns (beta) |
| 3 | +weight: 10 |
| 4 | +--- |
| 5 | + |
| 6 | +Icon columns provide a way to display icons in your table without having to use `format()` or partial views. |
| 7 | + |
| 8 | +### setIcon |
| 9 | +setIcon requires a valid path to an SVG (Directly or via a Library), it receives the $row, and $value (if available) to help you customise which icon to use |
| 10 | +```php |
| 11 | +IconColumn::make('Icon', 'status') |
| 12 | + ->setIcon(function ($row, $value) { |
| 13 | + if($value == 1) { |
| 14 | + return "heroicon-o-check-circle"; |
| 15 | + } |
| 16 | + else |
| 17 | + { |
| 18 | + return "heroicon-o-x-circle"; |
| 19 | + } |
| 20 | + }), |
| 21 | +``` |
| 22 | + |
| 23 | +### attributes |
| 24 | +Attributes receives the $row, and $value (if available) to help you customise which attributes to apply, you may pass both classes, and other SVG specific attributes. |
| 25 | +```php |
| 26 | +IconColumn::make('Icon', 'status') |
| 27 | + ->setIcon(function ($row, $value) { if($value == 1) { return "heroicon-o-check-circle"; } else { return "heroicon-o-x-circle"; } }) |
| 28 | + ->attributes(function ($row, $value) { |
| 29 | + if($value == 1) { |
| 30 | + return [ |
| 31 | + 'class' => 'w-6 h-6', |
| 32 | + 'stroke' => '#008000' |
| 33 | + ]; |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + return [ |
| 38 | + 'class' => 'w-3 h-3', |
| 39 | + 'stroke' => '#FF0000' |
| 40 | + ]; |
| 41 | + } |
| 42 | + }), |
| 43 | +``` |
| 44 | + |
| 45 | +For example: |
| 46 | +### Example |
| 47 | +```php |
| 48 | +IconColumn::make('Icon', 'status') |
| 49 | + ->setIcon(function ($row, $value) { if($value == 1) { return "heroicon-o-check-circle"; } else { return "heroicon-o-x-circle"; } }) |
| 50 | + ->attributes(function ($row, $value) { |
| 51 | + if($value == 3) { |
| 52 | + return [ |
| 53 | + 'class' => 'w-3 h-3', |
| 54 | + 'stroke' => '#008000' |
| 55 | + ]; |
| 56 | + } |
| 57 | + else if($value == 2) { |
| 58 | + return [ |
| 59 | + 'class' => 'w-3 h-3', |
| 60 | + 'stroke' => '#0000FF' |
| 61 | + ]; |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + return [ |
| 66 | + 'class' => 'w-3 h-3', |
| 67 | + 'stroke' => '#FF0000' |
| 68 | + ]; |
| 69 | + } |
| 70 | + }), |
| 71 | +``` |
| 72 | + |
| 73 | +Please also see the following for other available methods: |
| 74 | +<ul> |
| 75 | + <li> |
| 76 | + <a href="https://rappasoft.com/docs/laravel-livewire-tables/v3/columns/available-methods">Available Methods</a> |
| 77 | + </li> |
| 78 | + <li> |
| 79 | + <a href="https://rappasoft.com/docs/laravel-livewire-tables/v3/columns/column-selection">Column Selection</a> |
| 80 | + </li> |
| 81 | + <li> |
| 82 | + <a href="https://rappasoft.com/docs/laravel-livewire-tables/v3/columns/secondary-header">Secondary Header</a> |
| 83 | + </li> |
| 84 | + <li> |
| 85 | + <a href="https://rappasoft.com/docs/laravel-livewire-tables/v3/columns/footer">Footer</a> |
| 86 | + </li> |
| 87 | +</ul> |
0 commit comments