aayaresko/laravel-table

Simple HTML table builder for laravel 5

v1.0.4 2016-10-31 09:16 UTC

This package is not auto-updated.

Last update: 2024-12-21 21:20:03 UTC


README

HTML table builder for laravel 5

Installation

The preferred way to install extension is via composer. Check the composer.json for this extension's requirements and dependencies. To install, either run

$ php composer.phar require aayaresko/laravel-table

or add

"aayaresko/laravel-table": "^1.0"

to the require section of your composer.json.

Configuration

It does not require any additional configuration.

Usage

Simply create a new instance of TablesFacade and pass to it all required parameters:

$table = new TablesFacade($data_provider, $attributes, $default_actions_route);

$data_provider is used as a models source. It should be either an instance of Illuminate\Contracts\Pagination\LengthAwarePaginator or Illuminate\Database\Eloquent\Collection.

$attributes array holds list of attributes, that should be rendered in each table row. You can use 'dot' syntax to target attribute value of related models:

$table = new TablesFacade(
    $data_provider, 
    [
        'nickname',
        'email',
        'profile.full_name',
        'created',        
    ], 
    $default_actions_route
);

In your view you should place something like this:

<div class="table-responsive">
    {{ $table->renderTable() }}
    {{ $table->renderLinks() }}
</div>

You scan use renderLinks() method only when you use Illuminate\Contracts\Pagination\LengthAwarePaginator as $data_provider.

You can specify custom column name for any attribute:

$table = new TablesFacade(
    $data_provider, 
    [
        'Alias' => 'nickname',
        'email',
        'Full name' => 'profile.full_name',
    ], 
    $default_actions_route
);

That custom name will be translated automatically.

You can attach a callback to render any attribute value:

$table = new TablesFacade(
    $data_provider, 
    [
        'nickname',
        'email',
        'profile.full_name',
        'created',   
        'alias' => function ($model) {
            return $model->alias;
        }
    ], 
    $default_actions_route
);

Function signature is pretty straightforward: function ($model) {}.

$default_actions_route is route which will be used as 'parent' to generate links for all action buttons. You can set <$default_actions_route to 'false'.

You can configure your own list of action buttons via $action_buttons property.

'show' => [
    'title' => '<i class="glyphicon glyphicon-eye-open"></i>',
    'route' => 'backend.accounts',
],
'edit' => [
    'title' => '<i class="glyphicon glyphicon-pencil"></i>',
    'route' => 'frontend.accounts',
],
'destroy' => [
    'title' => 'My button content',
    'url' => 'backend/accounts/destroy'
    'options' => [
        'class' => 'delete-ajax',
    ]
]

Please be aware that route and url options are mutually exclusive. You can remove $action_buttons column by setting 'false' as $action_buttons value. You can specify any html options for any button via button options array.

You can specify attributes values for the table itself, tr and td tags of the table via $table_options, $row_options and $item_options respectively. You can specify text, which will be displayed in case of no models via $not_found_text.