Convert Figma logo to code with AI

rappasoft logolaravel-livewire-tables

A dynamic table component for Laravel Livewire

1,772
331
1,772
22

Top Related Projects

jQuery DataTables API for Laravel

Quick Overview

Laravel Livewire Tables is a dynamic, responsive table component for Laravel Livewire. It provides a powerful and flexible way to create data tables with features like sorting, filtering, and pagination, all without writing JavaScript.

Pros

  • Easy integration with Laravel and Livewire projects
  • Highly customizable with a wide range of built-in features
  • Responsive design out of the box
  • Real-time updates without page reloads

Cons

  • Learning curve for developers new to Livewire
  • Limited to Laravel and Livewire ecosystem
  • May require additional configuration for complex use cases
  • Performance can be impacted with large datasets

Code Examples

  1. Basic table setup:
use Rappasoft\LaravelLivewireTables\DataTableComponent;

class UsersTable extends DataTableComponent
{
    public function columns(): array
    {
        return [
            Column::make('Name'),
            Column::make('Email'),
            Column::make('Created At'),
        ];
    }

    public function query()
    {
        return User::query();
    }
}
  1. Adding custom filters:
public function filters(): array
{
    return [
        'status' => Filter::make('Status')
            ->select([
                '' => 'All',
                'active' => 'Active',
                'inactive' => 'Inactive',
            ]),
    ];
}
  1. Implementing bulk actions:
public function bulkActions(): array
{
    return [
        'delete' => ['title' => 'Delete', 'icon' => 'trash'],
    ];
}

public function delete()
{
    User::whereIn('id', $this->getSelected())->delete();
    $this->clearSelected();
}

Getting Started

  1. Install the package:
composer require rappasoft/laravel-livewire-tables
  1. Create a new Livewire component:
php artisan make:livewire UsersTable
  1. Extend the DataTableComponent in your new component:
use Rappasoft\LaravelLivewireTables\DataTableComponent;

class UsersTable extends DataTableComponent
{
    public function columns(): array
    {
        return [
            Column::make('Name'),
            Column::make('Email'),
        ];
    }

    public function query()
    {
        return User::query();
    }
}
  1. Use the component in your Blade view:
<livewire:users-table />

Competitor Comparisons

jQuery DataTables API for Laravel

Pros of Laravel DataTables

  • Mature and well-established package with extensive documentation
  • Supports server-side processing for handling large datasets efficiently
  • Offers a wide range of customization options and plugins

Cons of Laravel DataTables

  • Relies on jQuery, which may not be ideal for modern JavaScript frameworks
  • Can be more complex to set up and configure compared to Livewire Tables
  • May require more server-side code for advanced functionality

Code Comparison

Laravel DataTables:

return DataTables::of(User::query())
    ->addColumn('action', function ($user) {
        return '<a href="#">Edit</a>';
    })
    ->make(true);

Laravel Livewire Tables:

public function columns(): array
{
    return [
        Column::make('Name'),
        Column::make('Email'),
        Column::make('Action')->format(fn($value, $row) => view('actions', ['user' => $row])),
    ];
}

Both packages offer powerful table functionality for Laravel applications. Laravel DataTables excels in handling large datasets and offers extensive customization, while Laravel Livewire Tables provides a more modern, JavaScript-free approach with tighter integration into the Laravel ecosystem. The choice between them depends on project requirements, performance needs, and developer preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Package Logo

Latest Version on Packagist Styling Tests Total Downloads codecov PHP Stan Level 5

Enjoying this package? Buy me a beer 🍺

A dynamic Laravel Livewire component for data tables.

Dark Mode

Full Table

Bootstrap 4 Demo | Bootstrap 5 Demo | Tailwind Demo | Demo Repository

Installation

You can install the package via composer:

composer require rappasoft/laravel-livewire-tables

You must also have Alpine.js version 3 or greater installed and available to the component.

Documentation and Usage Instructions

See the documentation for detailed installation and usage instructions.

Basic Example

<?php

namespace App\Http\Livewire\Admin\User;

use App\Domains\Auth\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

class UsersTable extends DataTableComponent
{
    protected $model = User::class;

    public function configure(): void
    {
        $this->setPrimaryKey('id');
    }

    public function columns(): array
    {
        return [
            Column::make('ID', 'id')
                ->sortable(),
            Column::make('Name')
                ->sortable(),
        ];
    }
}

See advanced example

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please e-mail anthony@rappasoft.com to report any security vulnerabilities instead of the issue tracker.

Credits

License

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