yuisalabs/voltia-datatable

Modern DataTable for Laravel Inertia.js. Clean syntax, customizable, testable and production ready UX

Fund package maintenance!
yuisa

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/yuisalabs/voltia-datatable

v0.1.1 2025-11-15 08:31 UTC

This package is not auto-updated.

Last update: 2026-01-11 07:30:57 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Modern, elegant DataTable package for Laravel with Inertia.js support. Built with clean syntax, fully customizable, and production-ready.

โœจ Features

  • ๐Ÿš€ Easy to use - Simple, fluent API for defining tables
  • ๐Ÿ” Full-text search - Search across multiple columns
  • ๐Ÿ”„ Sorting - Sort by any column with direction control
  • ๐Ÿ“Š Filters - Multiple filter types (Select, Text, Boolean, DateRange)
  • ๐Ÿ“„ Pagination - Built-in pagination with customizable per-page options
  • ๐ŸŽฏ Type-safe - Full PHP 8.3+ type hints
  • ๐Ÿ”— Eager loading - Automatic relationship eager loading
  • โšก Performance - Optimized queries for large datasets
  • ๐ŸŽจ Inertia.js ready - Perfect for Vue/React frontends

๐Ÿ“ฆ Installation

Install the package via composer:

composer require yuisalabs/voltia-datatable

Publish the config file:

php artisan vendor:publish --tag="voltia-datatable-config"

๐Ÿš€ Quick Start

1. Generate a DataTable Class

php artisan make:datatable UserTable --model=User

This creates app/Tables/UserTable.php:

<?php

namespace App\Tables;

use Illuminate\Database\Eloquent\Builder;
use App\Models\User;
use Yuisalabs\VoltiaDatatable\Table;
use Yuisalabs\VoltiaDatatable\Column;
use Yuisalabs\VoltiaDatatable\Filters\SelectFilter;
use Yuisalabs\VoltiaDatatable\Filters\DateRangeFilter;

class UserTable extends Table
{
    public function query(): Builder
    {
        return User::query();
    }

    public function columns(): array
    {
        return [
            Column::make('id', 'ID')
                ->sortable(),
            
            Column::make('name', 'Name')
                ->sortable()
                ->searchable(),
            
            Column::make('email', 'Email')
                ->sortable()
                ->searchable(),
            
            Column::make('status', 'Status')
                ->sortable()
                ->format(fn ($row, $value) => ucfirst($value)),
            
            Column::make('created_at', 'Created At')
                ->sortable()
                ->format(fn ($row, $value) => $value?->format('Y-m-d H:i:s')),
        ];
    }

    protected function filters(): array
    {
        return [
            'status' => new SelectFilter('status', [
                'active' => 'Active',
                'inactive' => 'Inactive',
                'pending' => 'Pending',
            ]),
            'created_at' => new DateRangeFilter('created_at'),
        ];
    }
}

2. Use in Controller

<?php

namespace App\Http\Controllers;

use App\Tables\UserTable;
use Inertia\Inertia;

class UserController extends Controller
{
    public function index(UserTable $datatable)
    {
        return Inertia::render('Users/Index', [
            'datatable' => $datatable->make(),
        ]);
    }
}

3. Frontend (Vue/React Example)

The datatable returns a structured response:

{
  rows: [...],
  columns: [...],
  meta: {
    page: 1,
    perPage: 15,
    total: 100,
    from: 1,
    to: 15
  },
  sort: {
    sortBy: 'name',
    sortDirection: 'asc'
  },
  search: 'john',
  filters: {...}
}

๐Ÿ“– Usage

Column Definition

Column::make('key', 'Label')
    ->sortable()          // Enable sorting
    ->searchable()        // Enable searching
    ->hidden()            // Hide column
    ->align('center')     // Alignment: left, center, right
    ->minWidth(150)       // Minimum width in pixels
    ->format(fn ($row, $value) => ...) // Custom formatting

Working with Relationships

public function columns(): array
{
    return [
        Column::make('user.name', 'User Name')
            ->sortable()
            ->searchable(),
        
        Column::make('user.email', 'Email')
            ->searchable(),
    ];
}

The package automatically eager loads the user relationship!

Available Filters

SelectFilter

'status' => new SelectFilter('status', [
    'active' => 'Active',
    'inactive' => 'Inactive',
])

TextFilter

'search' => new TextFilter('column_name')

BooleanFilter

'is_verified' => new BooleanFilter('is_verified')

DateRangeFilter

'created_at' => new DateRangeFilter('created_at')

Custom Queries

public function query(): Builder
{
    return User::query()
        ->where('status', 'active')
        ->with('roles');
}

Custom Formatting

Column::make('price', 'Price')
    ->format(fn ($row, $value) => 'Rp ' . number_format($value, 0, ',', '.'))

Column::make('status', 'Status')
    ->format(fn ($row, $value) => match($value) {
        'active' => 'โœ… Active',
        'inactive' => 'โŒ Inactive',
        default => 'โธ Pending'
    })

โš™๏ธ Configuration

Published config file (config/voltia-datatable.php):

return [
    'default_per_page' => 15,
    'per_page_options' => [10, 15, 25, 50, 100],
    'max_per_page' => 100,
    'query_string' => true,
    'date_format' => 'Y-m-d',
];

๐Ÿงช Testing

composer test

๐Ÿ“ Changelog

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

๐Ÿค Contributing

Please see CONTRIBUTING for details.

๐Ÿ”’ Security

Please review our security policy on how to report security vulnerabilities.

๐Ÿ‘ฅ Credits

๐Ÿ“„ License

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