PHP code example of eawardie / data-grid-laravel
1. Go to this page and download the library: Download eawardie/data-grid-laravel 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/ */
eawardie / data-grid-laravel example snippets
$query = User::query();
$data = DataGrid::forQuery($query)
->addColumn('name', 'Name', 'text')
->get();
array:2 [▼
"items" => array:50 [▶]
"metaData" => array:12 [▶]
]
->addAdvancedColumn(function (ColumnDefinition $column) {
return $column->value('user.name')
->type('text')
->label('User')
->subtitle('client.name')
->subtitleType('text');
})
$query = User::query();
$data = DataGrid::forQuery($query)
->addIconColumn('user.mobile_verified_at', 'Verified', function (IconDefinition $icon) {
return $icon->condition('account-lock', '=', null, 'error', 'No Password')
->condition('account-check', '!=', null, 'success', 'Has Password');
})
$query = User::query()->leftJoin('client', 'user.clientid', '=', 'client.clientid');
$data = DataGrid::forQuery($query)
->addColumn('user.name', 'Name', 'text')
->addColumn('client.name', 'Client', 'text')
->views(function (ViewDefinition $view) {
return $view->column('client.name')
->label('Clients');
})
$query = User::query();
$data = DataGrid::forQuery($query)
->addSelect('mobile')
->addColumn('name', 'Name', 'text')
->mapRow(function ($row) {
return collect($row)
->put('has_mobile', !!$row['mobile'])
->toArray();
})
function (ViewDefinition $view) use ($progressRaw) {
return $view->column('name')
->column('progress', true)
function (ViewDefinition $view) use ($progressRaw) {
return $view->column('name')
->column('progress')
->search(['name' => ['john']])
->sortBy(['name' => 'asc'])
->filters([progress => ['value' => 50, 'operator' => '<']])
bash
php artisan vendor:publish --tag="data-grid-migrations"
php artisan migrate