laravolt / suitable
Semantic-UI table builder for Laravel application
v4.0.2
2020-02-21 01:34 UTC
Requires
- php: >=7.3
- illuminate/auth: ^6.0
- illuminate/support: ^6.0
- laravolt/support: ^4.0.2
- niklasravnsborg/laravel-pdf: ^4.0
- rap2hpoutre/fast-excel: ^1.3.1
- dev-master / 4.1.x-dev
- v4.0.2
- v4.0.1
- 3.6.12
- 3.6.11
- 3.6.10
- 3.6.9
- 3.6.8
- 3.6.7
- 3.6.6
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.14
- 3.3.13
- 3.3.12
- 3.3.11
- 3.3.10
- 3.3.9
- 3.3.8
- 3.3.7
- 3.3.6
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.x-dev
- 2.7.0
- 2.6.0
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1
- dev-dev
This package is auto-updated.
Last update: 2024-10-25 21:54:49 UTC
README
Semantic-UI table builder for Laravel.
Version Compatibility
Installation
Install Package
composer require laravolt/suitable
Service Provider
Skip this step for Laravel >= 5.5.
Laravolt\Suitable\ServiceProvider::class,
Facade
Skip this step for Laravel >= 5.5.
'Suitable' => Laravolt\Suitable\Facade::class,
Usage
Basic
{!! Suitable::source(User::all()) ->columns([ \Laravolt\Suitable\Columns\Numbering::make('No'), ['header' => 'Nama', 'field' => 'name'], ['header' => 'Email', 'field' => 'email'], ]) ->render() !!}
Columns Definition
field
{!! Suitable::source(User::all()) ->columns([ ['header' => 'Email', 'field' => 'email'], ['header' => 'Bio', 'field' => 'profile.bio'], // nested attribute ]) ->render() !!}`
view
{!! Suitable::source(User::all()) ->columns([ ['header' => 'Address', 'view' => 'components.address'], ]) ->render() !!}`
views/components/address.blade.php
<address> Address:<br> {{ $data->address_1 }}<br> {{ $data->address_2 }}<br> {{ $data->city }}, {{ $data->state }} </address>
raw
{!! Suitable::source(User::all()) ->columns([ [ 'header' => 'Roles', 'raw' => function($data){ // do anything here and don't forget to return String return $data->roles->implode('name', ', '); // output: "role1, role2, role3" } ], ]) ->render() !!}`
ColumnInterface
{!! Suitable::source(User::all()) ->columns([ new \App\Columns\StatusColumn('Status'), ]) ->render() !!}
Contract
<?php namespace Laravolt\Suitable\Columns; interface ColumnInterface { public function header(); public function headerAttributes(); public function cell($cell, $collection, $loop); public function cellAttributes($cell); public function sortable(); }
Implementation
StatusColumn.php
<?php namespace App\Columns; use Laravolt\Suitable\Columns\ColumnInterface; class StatusColumn implements ColumnInterface { protected $header; public function __construct($header) { $this->header = $header; } public function header() { return $this->header; } public function cell($cell, $collection, $loop) { return sprintf("<div class='ui label'>%s</div>", $cell->status); } public function headerAttributes() { return []; } public function cellAttributes($cell) { return []; } }
Advance Usage
Auto Detect
<?php namespace App\Http\Controllers; use App\User; use Illuminate\Routing\Controller; use Laravolt\Suitable\Plugins\Pdf; use Laravolt\Suitable\Plugins\Spreadsheet; use Laravolt\Suitable\Tables\BasicTable; class SuitableController extends Controller { public function __invoke() { $table = (new BasicTable(new User())); return $table->view('etalase::example.suitable'); } }
Custom TableView
TableView Definition
<?php namespace App\Table; use Laravolt\Suitable\Columns\Date; use Laravolt\Suitable\Columns\DateTime; use Laravolt\Suitable\Columns\Id; use Laravolt\Suitable\Columns\Numbering; use Laravolt\Suitable\Columns\Text; use Laravolt\Suitable\TableView; class UserTable extends TableView { protected function columns() { return [ Numbering::make('No'), Id::make('id'), Text::make('name'), Text::make('email'), Date::make('created_at'), DateTime::make('updated_at'), ]; } }
<?php namespace Laravolt\Etalase\Http\Controllers; use App\User; use Illuminate\Routing\Controller; use App\Table\UserTable; use Laravolt\Suitable\Plugins\Pdf; use Laravolt\Suitable\Plugins\Spreadsheet; class SuitableController extends Controller { public function __invoke() { $users = User::autoSort()->paginate(5); $userTable = new UserTable($users); $table = $userTable ->plugins([ (new Pdf('users.pdf')), (new Spreadsheet('users.xls')), ]); return $table->view('etalase::example.suitable'); } }
Built In Columns
Laravolt\Suitable\Columns\Avatar
Laravolt\Suitable\Columns\Boolean
Laravolt\Suitable\Columns\Checkall
Laravolt\Suitable\Columns\Date
Laravolt\Suitable\Columns\DateTime
Laravolt\Suitable\Columns\Id
Laravolt\Suitable\Columns\Image
Laravolt\Suitable\Columns\Numbering
Laravolt\Suitable\Columns\Raw
Laravolt\Suitable\Columns\RestfulButton
Laravolt\Suitable\Columns\Text
Laravolt\Suitable\Columns\View
Roadmap
- Rename
TableView
toTable
- Rename Toolbars to
Segment\Item
- Rename DropdownFilter to
DropdownLink