An advanced datatable component for Laravel Livewire.

Overview

Livewire Smart Table

An advanced, dynamic datatable component with pagination, sorting, and searching including json data.

Livewire Smart Table Demo

Installation

You can install the package via composer:

composer require tkaratug/livewire-smart-table

Requirements

This package uses livewire/livewire (https://laravel-livewire.com/) under the hood.

It also uses Tailwind (https://tailwindcss.com) for base styling.

Please make sure you include both of these dependencies before using this component.

Usage

In order to use this component, you must create a new Livewire component that extends from LivewireSmartTable

You can use make:livewire to create a new component. For example.

php artisan make:livewire UserList

In the UserList class, instead of extending from the base Livewire Component class, extend from LivewireSmartTable class. Also, remove the render method. You'll have a class similar to this snippet.

In this class, you must define columns that you want to show in a table.

class UserList extends LivewireSmartTable
{
    $columns = [
        'id' => [
            'type' => 'string', // column type
            'name' => 'Id', // column header
            'class' => 'text-danger', // column class
        ],
        'name' => [
            'type' => 'string',
            'name' => 'Name',
        ],
        'email' => [
            'type' => 'string',
            'name' => 'E-Mail',
        ],
    ];
}

Keys of columns array must be the same as column names in database table or key of a json object.

To render the component in a view, just use the Livewire tag or include syntax.

<livewire:user-list :query="$query" />

$query must be instance of an Eloquent Collection.

For example, create a UserController class, select users to show in a table and pass them to a view file.

class UserController extends Controller
{
    public function index()
    {
        $users = App\User::where('is_active', '=', true)->get();

        return view('users', ['users' => $users]);
    }
}

Then in users.blade.php use Livewire tag and give users to query attribute.

<livewire:user-list :query="$users" />

Column Properties

string

It is used for showing data as string in HTML table.

link

It is used for showing data as link in HTML table.

In addition to type, you must define a url to redirect when clicked.

$columns = [
    'profile' => [
        'type' => 'link',
        'url' => 'http://example.com/users/{id}/profile',
        'target' => '_blank'
    ],
];

It is also possible to give parameters to the URL. All you need to do is give the column name containing the data you want to pass to the url in curly braces.

Let's say you have a database table contains blog posts and each post has a slug. To show post titles in html table as a link, you need to define column as follows:

'title' => [
    'type' => 'link',
    'url' => 'http://example.com/posts/{slug}',
];

The component is smart enough to find the slug field of current record and give it to the url.

json

It is used for showing data from json columns. If you have a json column in your database table, you can show values from it in html table.

Let's say you have a json column named contact in your database table and contains address details in it.

{"address":{"country":"Turkey","city":"Istanbul","state":"Besiktas"}}

To show just the city in html table, you need to define column as follows:

'city' => [
    'type' => 'json',
    'name' => 'City', // Text for column header
    'from' => 'contact', // field that contains json data in a db table
    'value' => 'address.city' // nested json value
];

It will find the json data from contact column, and take city value inside address key then show it on the table.

actions

It is used for showing action links for each row in html table.

You need to give element and url keys for the html element of the link and url to redirect.

'actions' => [
    'type' => 'actions',
    'name' => 'Actions', // Text for column header
    'actions' => [
        [
            'element' => '<button>View</button>',
            'url' => 'http://example.com/users/{id}/profile'
        ],
        [
            'element' => '<button>Edit</button>',
            'url' => 'http://example.com/users/{id}/edit'
        ],
    ]
];

Publishing Views

You can also publish the view files to customize them.

All you need to do is running the following command. Then the views will be copied into /resources/views/vendor/livewire-smart-table directory.

php artisan vendor:publish --tag=livewire-smart-table-views

Testing

composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About Wire Elements Spotlight Wire Elements Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel applic

A dynamic table component for Laravel Livewire - For Slack access, visit:
A dynamic table component for Laravel Livewire - For Slack access, visit:

A dynamic Laravel Livewire component for data tables. Bootstrap 4 Demo | Bootstrap 5 Demo | Tailwind Demo | Demo Repository Installation You can insta

A dynamic Laravel Livewire component for multi steps form
A dynamic Laravel Livewire component for multi steps form

Livewire component that provides you with a wizard that supports multiple steps form while maintaining state.

Livewire component that provides you with a modal that supports multiple child modals while maintaining state.
Livewire component that provides you with a modal that supports multiple child modals while maintaining state.

About LivewireUI Modal LivewireUI Modal is a Livewire component that provides you with a modal that supports multiple child modals while maintaining s

Livewire component that provides you with a modal that supports multiple child modals while maintaining state.
Livewire component that provides you with a modal that supports multiple child modals while maintaining state.

About Wire Elements Modal Wire Elements Modal is a Livewire component that provides you with a modal that supports multiple child modals while maintai

Livewire component for dependant and/or searchable select inputs
Livewire component for dependant and/or searchable select inputs

Livewire Select Livewire component for dependant and/or searchable select inputs Preview Installation You can install the package via composer: compos

Render a Livewire component on a specific target in the DOM.

Livewire Portals Render a Livewire component on a specific target in the DOM. Install THIS PACKAGE IS STILL IN DEVELOPMENT, TO USE, PLEASE ADD THE FOL

This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

Advanced Laravel models filtering capabilities

Advanced Laravel models filtering capabilities Installation You can install the package via composer: composer require pricecurrent/laravel-eloquent-f

Releases(v1.4.0)
Owner
Turan Karatuğ
Turan Karatuğ
Belich Tables: a datatable package for Laravel Livewire

Belich Tables is a Laravel package base on Livewire and AlpineJS that allows you to create scaffold datatables with search, column sort, filters, pagination, etc...

Damián Aguilar 11 Aug 26, 2022
⚡ PowerGrid generates Advanced Datatables using Laravel Livewire.

?? Documentation | ?? Features | ⌨️ Get started Livewire ⚡ PowerGrid ⚡ PowerGrid creates modern, powerful and easy to customize Datatables based on La

Power Components ⚡ 962 Jan 2, 2023
rapyd: crud widgets for laravel. datatable, grids, forms, in a simple package

rapyd-laravel This is a pool of presentation and editing widgets (Grids and Forms) for laravel. Nothing to "generate", just some classes to let you de

Felice Ostuni 875 Dec 29, 2022
Joy VoyagerDatatable module adds Yajra DataTable to Voyager.

Joy VoyagerDatatable This Laravel/Voyager module adds Yajra Async/Ajax DataTable to Voyager. By ?? Ramakant Gangwar. Prerequisites Composer Installed

Ramakant Gangwar 10 Dec 19, 2022
Laravel-comments-livewire - Livewire components for the laravel-comments package

Associate comments and reactions with Eloquent models This package contains Livewire components to be used with the spatie/laravel-comments package. S

Spatie 15 Jan 18, 2022
Laravel Livewire full page component routing.

Laravel Livewire Routes Laravel Livewire full page component routing. This package allows you to specify routes directly inside your full page Livewir

null 22 Oct 6, 2022
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About LivewireUI Spotlight LivewireUI Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel application.

Livewire UI 792 Jan 3, 2023
A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards.

TALL multiselect cards A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards. Table of content

Frederic Habich 19 Dec 14, 2022
Laravel Livewire component to show Events in a good looking monthly calendar

Livewire Calendar This package allows you to build a Livewire monthly calendar grid to show events for each day. Events can be loaded from within the

Andrés Santibáñez 680 Jan 4, 2023