Quick Start
You can install the package via composer:
composer require settleup/datagridsConfiguration
Optionally, you can publish the config using
php artisan vendor:publish --tag="datagrids-config"DataGrid Registration
DataGrids are registered manually using the Route::dataGrid() macro. This should be placed in your routes file:
Route::dataGrid(ActiveUserDataGrid::class);Usage
To create a new grid, you need to define a class that extends the DataGrid class and implements the required methods. To make this easier, we've added a make command that can be invoked with php artisan make:datagrid {name}. Below is a sample of a grid class:
<?php
namespace App\DataGrids;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use SettleUp\Visualizations\DataGrids\Abstracts\DataGrid;
use SettleUp\Visualizations\DataGrids\Actions\Action;
use SettleUp\Visualizations\DataGrids\Columns\Number;
use SettleUp\Visualizations\DataGrids\Columns\Text;
use SettleUp\Visualizations\Data\SortData;
use SettleUp\Visualizations\Enums\SortOperator;
use SettleUp\Visualizations\FloatingFilters\DateRange;
class ActiveUserDataGrid extends DataGrid
{
public function getColumns(): Collection
{
return collect([
Number::make('users.id', 'ID')
->asRowKey(),
Text::make('users.name', 'Name'),
Text::make('users.email', 'Email'),
]);
}
public function getQuery(): Builder
{
return DB::table('users');
}
public function getDefaultSorts(): Collection
{
return collect([
SortData::make('ID', SortOperator::ASC),
]);
}
public function getInlineActions(): Collection
{
return collect([
Action::make('Edit', fn (): array => [
'ran' => true,
])->withAuthorization('edit-users'),
]);
}
public function getBulkActions(): Collection
{
return collect([
Action::make('Create', fn (): array => [
'ran' => true,
])->withAuthorization('create-users'),
]);
}
public function getFloatingFilters(): Collection
{
return collect([
DateRange::make('DATE(users.created_at)', 'Joined On'),
]);
}
}In this example, the ActiveUserDataGrid class defines the columns and the query for the grid. The getColumns method returns a collection of columns, and the getQuery method returns the query builder instance for the grid.
Once created, and registered, new routes will become available. Using the ActiveUserDataGrid as an example, the following routes will be registered:
POST grids/active-users/actions/bulk .................. grids.active-users.actions.bulk
POST grids/active-users/actions/inline ................ grids.active-users.actions.inline
POST grids/active-users/data .......................... grids.active-users.data
POST grids/active-users/schema ........................ grids.active-users.schema
GET|HEAD grids/active-users/views ......................... grids.active-users.views
POST grids/active-users/views ......................... grids.active-users.views.store
DELETE grids/active-users/views/{view} .................. grids.active-users.views.destroy