tooinfinity/inertia-tank-table

handle inertia server side table with tank table

dev-main 2025-04-26 21:07 UTC

This package is auto-updated.

Last update: 2025-04-26 21:18:58 UTC


README

A Laravel package that provides a powerful table component for Inertia.js + React applications with TanStack Table integration. Built to handle server-side operations efficiently with features like sorting, filtering, pagination, and exports.

Features

  • 🔄 Server-side sorting, filtering, and pagination
  • 🔍 Global search across multiple fields
  • ⚡ TanStack Table integration for optimal performance
  • 📊 Multiple column types (Text, Numeric, Date, Actions)
  • 🔎 Advanced filtering options
  • ⚙️ Customizable row actions
  • 📑 Export to Excel, CSV, and PDF
  • 🎨 Tailwind CSS styling
  • 🔒 Secure export handling with signed URLs

Installation

composer require tooinfinity/inertia-tank-table

Publish the configuration and assets:

php artisan vendor:publish --provider="TooInfinity\InertiaTankTable\InertiaTankTableServiceProvider"

Quick Start

  1. Create a new table class:
php artisan make:tank-table Users
  1. Define your table configuration in app/Tables/Users.php:
class Users extends TankTable
{
    protected string $model = User::class;
    protected string $defaultSort = 'name';
    protected array $searchableFields = ['name', 'email'];

    protected function buildQuery(): Builder
    {
        return User::query();
    }

    protected function getColumns(): array
    {
        return [
            (new TextColumn('name', 'Full Name'))->sortable(),
            (new TextColumn('email', 'Email'))->sortable(),
            // Add more columns...
        ];
    }
}
  1. Use in your Inertia controller:
public function index()
{
    return Inertia::render('Users/Index', [
        'users' => \App\Tables\Users::make()
    ]);
}
  1. In your React component:
import { TankTable } from '@/Components/TankTable';

export default function Users({ users }) {
    return (
        <TankTable
            {...users}
            signedExportUrl={usePage().props.tankTableExportUrl}
            tableClass="App\\Tables\\Users"
        />
    );
}

Available Column Types

  • TextColumn: For text and string values
  • NumericColumn: For numbers with optional formatting
  • DateColumn: For dates with customizable formats
  • ActionColumn: For row actions like edit, delete, etc.

Filters

Available filter types:

  • TextFilter: Text search
  • NumericFilter: Number range filtering
  • BooleanFilter: Yes/No filters
  • DateFilter: Date range with nullable option

Exports

Supported export formats:

  • Excel (.xlsx)
  • CSV
  • PDF

Row Actions

Built-in action types:

  • EditAction: Link-based edit action
  • DeleteAction: Delete with confirmation
  • StatusAction: Custom status toggle actions

Configuration

You can customize the default settings in config/inertia-tank-table.php:

return [
    'pagination' => [
        'per_page' => 10,
        'page_name' => 'page',
    ],
    'sort' => [
        'direction' => 'asc',
    ],
    'namespace' => 'App\\Tables',
];

Security

Exports are protected with signed URLs and middleware to prevent unauthorized access.

Requirements

  • PHP 8.3+
  • Laravel 11.0+
  • Inertia.js 2.0+
  • React 18+

License

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