2017 © Pedro Peláez
 

library laravel-table

Table functionality for Laravel collections

image

merkeleon/laravel-table

Table functionality for Laravel collections

  • Friday, July 6, 2018
  • by codeator
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2,701 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 32 Versions
  • 31 % Grown

The README.md

Laravel table

Laravel module for table rendering, (*1)

Installation

First, require the package using Composer:, (*2)

composer require merkeleon/laravel-table, (*3)

Add to your config/app.php providers section, (*4)

Merkeleon\Table\Providers\TableServiceProvider::class, (*5)

and to facades section, (*6)

'Table' => Merkeleon\Table\Facades\Table::class, (*7)

Add the views and the localization files:, (*8)

php artisan vendor:publish --provider="Merkeleon\Table\Providers\TableServiceProvider", (*9)

Examples

Translations

Soon, (*10)

Table class

<?php

namespace App\Tables\Admin;

use App\Models\User;
use App\Models\Role;
use Table;
use Merkeleon\Table\Filter\SelectFilter;

class UsersTable extends Table
{

    public static function create() {
        $roles = Role::all()->pluck('name', 'id');
        $table = self::from(new User())
            ->columns([
                'id' => 'Id',
                'name' => 'Name',
                'email' => 'Email',
                'balance' => 'Balance',
                'created_at' => 'Created at'
            ])
            /*
            For filters allowed types: string, range, date
            */
            ->filters([
                'name' => 'string',
                /*
                String filter can be strict (key=value) or not (key like %value%)
                */
                'email' => 'string|strict:true',
                'role_id' => (new SelectFilter('role_id'))
                    ->options($roles)
                    ->label('Role'),
                /*
                You can specify settings for some of the filters.
                Eg: range filter can take multiplier as the argument
                 */
                'balance' => 'range|multiplier:10000',                
                'created_at' => 'date'
            ])
            /*
            For totals allowed types: sum, count
            */
            ->totals([
                'balance' => 'sum',
                'id' => 'count'
            ])
            /*
            Sometimes you need to filter results without input
            If User with moderation role can't view admin users
            */
            ->filterCallback(function($model) {
                if (auth()->user() && auth()->user()->role->type == Role::TYPE_MODERATOR) {
                    $model = $model->whereHas('role', function($query) {
                        $query->where('type', '<>', Role::TYPE_ADMIN);
                    });
                }
                return $model;
            })
            /*
            Group operations for query
            Label for delete batch action is: trans('table::batch.labels.delete');
            */
            ->batchActions([
                'delete' => function ($queryBuilder) {
                    $queryBuilder->delete();
                }
            ])
            ->sortables([
                'id'
            ])
            ->exporters(['csv'])
            /*
                Route name -> Link name in last column
            */
            ->actions([
                'admin.users.view' => 'View'
            ])
            ->orderBy('id', 'asc')
            ->paginate(20);

        return $table;
    }

}

Controller

<?php

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Tables\Admin\UsersTable;

class UsersController extends Controller
{

    public function index() {
        $table = UsersTable::create();

        return view('admin.users.index', [
            'table' => $table
        ]);
    }

}

View

@extends('admin.layout')

@section('content')
    {!! $table->render() !!}
@stop

Sample Sass based on bootstrap v4

.table {
  tbody {
    .ctable-total-content {
      border: none;
      background-color: transparent !important;

      td {
        border: none;
        background-color: transparent;
        font-size: 80%;
        padding-top: 0;
      }
    }

    .ctable-total-heading {
      border: none;
      background-color: transparent !important;

      td {
        border: none;
        background-color: transparent;
        font-size: 80%;
        font-weight: bold;
      }
    }

    tr:nth-of-type(even) {
      td.ctable-ordered {
        background-color: rgba(0, 0, 0, 0.10);
      }
    }

    tr:nth-of-type(odd) {
      td.ctable-ordered {
        background-color: rgba(0, 0, 0, 0.17);
      }
    }
  }

  thead {
    a {
      text-decoration: none;
    }
  }

  .table-arrow-up:before {
    font: normal normal normal 16px/1 "Material Design Icons";
    content: mdi('arrow-up');
    text-decoration: none;
  }

  .table-arrow-down:before {
    font: normal normal normal 16px/1 "Material Design Icons";
    content: mdi('arrow-down');
    text-decoration: none;
  }
}

Some recommendations for JS

Use Flatpickr library for datepicker, (*11)

require('flatpickr')('[data-toggle=datepicker]');

The Versions

06/07 2018

dev-master

9999999-dev

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

06/07 2018

1.4.4

1.4.4.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

07/06 2018

1.4.3

1.4.3.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

29/05 2018

1.4.2

1.4.2.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

14/05 2018

1.4.1

1.4.1.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

14/05 2018

1.4.0

1.4.0.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

04/05 2018

1.3.2

1.3.2.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

01/05 2018

1.3.1

1.3.1.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

27/04 2018

1.3.0

1.3.0.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

by Avatar codeator

laravel model html table filtering sorting merkeleon

09/02 2018

1.2.1

1.2.1.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

08/02 2018

1.2.0

1.2.0.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

22/01 2018

1.1.5

1.1.5.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

12/01 2018

1.1.0

1.1.0.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

12/01 2018

1.1.4

1.1.4.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

22/12 2017

1.0.18

1.0.18.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

27/10 2017

1.0.17

1.0.17.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

13/10 2017

1.0.15

1.0.15.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

13/10 2017

1.0.16

1.0.16.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

13/10 2017

1.0.14

1.0.14.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

10/10 2017

1.0.13

1.0.13.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

26/09 2017

1.0.12

1.0.12.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

21/09 2017

1.0.11

1.0.11.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

20/09 2017

1.0.10

1.0.10.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

14/09 2017

1.0.9

1.0.9.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

28/08 2017

1.0.8

1.0.8.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

23/08 2017

1.0.7

1.0.7.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

21/08 2017

1.0.5

1.0.5.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

02/08 2017

1.0.4

1.0.4.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

01/08 2017

1.0.3

1.0.3.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

24/07 2017

1.0.2

1.0.2.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

19/04 2017

v1.0.1

1.0.1.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon

19/04 2017

v1.0.0

1.0.0.0

Table functionality for Laravel collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar codeator

laravel model html table filtering sorting merkeleon