Semantic-UI table builder for Laravel.
Laravel | Suitable |
---|---|
5.2.x | 1.x |
5.3.x | 2.x |
5.4.x | 2.x |
5.5.x | 2.x |
5.6.x | 2.x |
5.7.x | 2.x |
5.8.x | 3.x |
composer require laravolt/suitable
Skip this step for Laravel >= 5.5.
Laravolt\Suitable\ServiceProvider::class,
Skip this step for Laravel >= 5.5.
'Suitable' => Laravolt\Suitable\Facade::class,
{!! Suitable::source(User::all())
->columns([
\Laravolt\Suitable\Columns\Numbering::make('No'),
['header' => 'Nama', 'field' => 'name'],
['header' => 'Email', 'field' => 'email'],
])
->render() !!}
{!! Suitable::source(User::all())
->columns([
['header' => 'Email', 'field' => 'email'],
['header' => 'Bio', 'field' => 'profile.bio'], // nested attribute
])
->render() !!}`
{!! 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>
{!! 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() !!}`
{!! Suitable::source(User::all())
->columns([
new \App\Columns\StatusColumn('Status'),
])
->render() !!}
<?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();
}
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 [];
}
}
<?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');
}
}
<?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');
}
}
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
- Rename
TableView
toTable
- Rename Toolbars to
Segment\Item
- Rename DropdownFilter to
DropdownLink