PHP code example of neoacevedo / laravel-gridview
1. Go to this page and download the library: Download neoacevedo/laravel-gridview library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
neoacevedo / laravel-gridview example snippets
...
/*
* Package Service Providers...
*/
neoacevedo\gridview\Providers\GridViewServiceProvider::class,
...
public function index(Request $request, int $page = 1, int $perPage = 5)
{
$data = [
[
'nombre' => 'Andres',
'fecha' => 1706200888,
'email' => '[email protected] ',
],
[
'nombre' => 'Jorge',
'fecha' => 1706200890,
'email' => '[email protected] ',
],
[
'nombre' => 'Nelson',
'fecha' => 1706200990,
'email' => '[email protected] ',
],
[
'nombre' => 'Juan',
'fecha' => 1706201000,
'email' => '[email protected] ',
],
[
'nombre' => 'Pedro',
'fecha' => 1706201010,
'email' => '[email protected] ',
],
[
'nombre' => 'Felipe',
'fecha' => 1706201020,
'email' => '[email protected] ',
],
[
'nombre' => 'Fredy',
'fecha' => 1706201030,
'email' => '[email protected] ',
],
[
'nombre' => 'Richard',
'fecha' => 1706201040,
'email' => '[email protected] ',
],
];
Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') {
$page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
return new LengthAwarePaginator($this->forPage($page, $perPage), $total ?: $this->count(), $perPage, $page, [
'path' => LengthAwarePaginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
});
$dataProvider = collect($data)->paginate(5);
return response()->view('index', compact('dataProvider'));
}
{{ gridview()->widget([
'dataProvider' => $dataProvider,
'tableOptions' => [
' id' => 'datatable',
'class' => 'dataTable'
],
'columns' => [
[
'attribute' => 'nombre',
'headerOptions' => ['data-sortable' => 'true']
],
[
'attribute' => 'fecha',
'format' => ['datetime', 'd/m/Y H:i:s']
],
'email:email:Email',
[
'class' => '\neoacevedo\gridview\Column\ActionColumn',
'header' => 'Actions'
]
]
]) }}
<x-package-gridview id="table" class="dataTable"
:dataProvider="$dataProvider" :columns="[
[
'attribute' => 'nombre',
'headerOptions' => ['data-sortable' => 'true']
],
'fecha:datetime', // Formato corto del ejemplo anterior de la columna de fecha.
'email:email:Email',
[
'class' => '\neoacevedo\gridview\Column\ActionColumn',
'header' => 'Actions'
]
]" />
php composer.phar
bash
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-assets
bash
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-view
bash
php artisan vendor:publish --provider="neoacevedo\\gridview\\Providers\\GridViewServiceProvider" --tag=gridview-component-view