Custom Field Html Link
This example demonstrates how to use a Custom Field to display a HTML Link.
ID
|
Name
|
Created At
|
---|---|---|
1
|
Click to Search
"Arkansas Possum Pie"
|
03/04/2024
|
2
|
Click to Search
"Albacore Tuna Melt"
|
18/05/2024
|
3
|
Click to Search
"борщ"
|
30/04/2024
|
4
|
Click to Search
"Bacalhau com natas"
|
21/04/2024
|
5
|
Click to Search
"Baba Ghanoush"
|
01/05/2024
|
6
|
Click to Search
"Bacon Cheeseburger"
|
17/05/2024
|
7
|
Click to Search
"Baked potato"
|
13/04/2024
|
8
|
Click to Search
"Baklava"
|
21/04/2024
|
9
|
Click to Search
"Bangers and mash"
|
03/04/2024
|
10
|
Click to Search
"Black Pudding"
|
18/05/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\Footer;use PowerComponents\LivewirePowerGrid\PowerGrid;use PowerComponents\LivewirePowerGrid\PowerGridComponent;use PowerComponents\LivewirePowerGrid\PowerGridFields; final class CustomFieldHtmlLinkTable extends PowerGridComponent{ public function setUp(): array { return [ Footer::make() ->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('Created At', 'created_at_formatted'), ]; }}
Code highlighting provided by Torchlight.dev
Here you can find all relevant packages installed on this demo.
Name
|
Version
|
Description
|
---|---|---|
laravel/framework
|
v11
|
The Laravel Framework.
|
livewire/livewire
|
v3.5.0
|
A front-end framework for Laravel.
|
openspout/openspout
|
v4.24.1
|
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
|
power-components/livewire-powergrid
|
5.x-dev
|
PowerGrid generates Advanced Datatables using Laravel Livewire.
|