laravolt / suitable by uyab

Semantic-UI table builder for Laravel application
15,364
8
4
Package Data
Maintainer Username: uyab
Maintainer Contact: bayu.hendra@javan.co.id (Bayu Hendra Winata)
Package Create Date: 2016-07-15
Package Last Update: 2020-02-25
Home Page: https://laravolt.dev
Language: PHP
License: MIT
Last Refreshed: 2024-12-14 15:04:32
Package Statistics
Total Downloads: 15,364
Monthly Downloads: 6
Daily Downloads: 1
Total Stars: 8
Total Watchers: 4
Total Forks: 5
Total Open Issues: 6

SUI-TABLE

Semantic-UI table builder for Laravel.

Version Compatibility

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

Installation

Install Package

composer require laravolt/suitable

Service Provider

Skip this step for Laravel 5.5 or above.

Laravolt\Suitable\ServiceProvider::class,

Facade

Skip this step for Laravel 5.5 or above.

'Suitable'  => Laravolt\Suitable\Facade::class,

Usage

Basic

{!! Suitable::source(User::all())
->id('table1')
->title('Users')
->tableClass('ui table')
->search(false)
->columns([
    new \Laravolt\Suitable\Components\Checkall(),
    ['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);
}
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 [];
    }
}

Built In Columns