Custom Field Html Link
This example demonstrates how to use a Custom Field to display a HTML Link.
ID
|
Name
|
Link
|
Created At
|
---|---|---|---|
1
|
Click to Search
"Arkansas Possum Pie"
|
Click to Search
"Arkansas Possum Pie"
|
26/09/2024
|
2
|
Click to Search
"Albacore Tuna Melt"
|
Click to Search
"Albacore Tuna Melt"
|
07/10/2024
|
3
|
Click to Search
"Π±ΠΎΡΡ"
|
Click to Search
"Π±ΠΎΡΡ"
|
26/09/2024
|
4
|
Click to Search
"Bacalhau com natas"
|
Click to Search
"Bacalhau com natas"
|
29/09/2024
|
5
|
Click to Search
"Baba Ghanoush"
|
Click to Search
"Baba Ghanoush"
|
03/10/2024
|
6
|
Click to Search
"Bacon Cheeseburger"
|
Click to Search
"Bacon Cheeseburger"
|
11/09/2024
|
7
|
Click to Search
"Baked potato"
|
Click to Search
"Baked potato"
|
03/10/2024
|
8
|
Click to Search
"Baklava"
|
Click to Search
"Baklava"
|
12/10/2024
|
9
|
Click to Search
"Bangers and mash"
|
Click to Search
"Bangers and mash"
|
03/10/2024
|
10
|
Click to Search
"Black Pudding"
|
Click to Search
"Black Pudding"
|
03/10/2024
|
Disclaimer: Table data is randomly generated for
illustrative purposes only. The information here is not a reflection of the actual market and does
not constitute business, financial, or medical advice.
<?php namespace App\Livewire\Examples\CustomFieldHtmlLinkTable; use App\Models\Dish;use Illuminate\Database\Eloquent\Builder;use Illuminate\Support\Carbon;use PowerComponents\LivewirePowerGrid\Column; use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;use PowerComponents\LivewirePowerGrid\PowerGridComponent;use PowerComponents\LivewirePowerGrid\PowerGridFields; final class CustomFieldHtmlLinkTable extends PowerGridComponent{ public string $tableName = 'custom-field-html-link-table'; public function setUp(): array { return [ PowerGrid::footer() ->showPerPage() ->showRecordCount(), ]; } public function datasource(): ?Builder { return Dish::query(); } public function fields(): PowerGridFields { return PowerGrid::fields() ->add('id') ->add('name') ->add('link', function ($dish) { return sprintf( 'Click to Search "<a target="_blank" class="underline text-blue-600 hover:text-blue-800 visited:text-purple-600" href="https://www.google.com/search?q=%s">%s</a>"', urlencode(e($dish->name)), e($dish->name) ); }) ->add('created_at_formatted', fn ($dish) => Carbon::parse($dish->created_at)->format('d/m/Y')); } public function columns(): array { return [ Column::make('ID', 'id'), Column::make('Name', 'link', 'name'), Column::make('Link', 'link', 'link'), Column::make('Created At', 'created_at_formatted'), ]; }}
Code highlighting provided by Torchlight.dev