givanov95/laravel-data-table
Composer 安装命令:
composer require givanov95/laravel-data-table
包简介
A server-side DataTable builder for Laravel with a matching Vue 3 + Inertia frontend.
README 文档
README
A server-side DataTable builder for Laravel that ships with a matching Vue 3 + Inertia frontend. Backend and frontend live in the same repository and are published as two separate packages:
| Package | Installer |
|---|---|
givanov95/laravel-data-table |
composer require givanov95/laravel-data-table |
@givanov95/vue-data-table |
npm install @givanov95/vue-data-table |
The two are designed to talk to each other through a single JSON payload, so you write your table definition once in PHP and the Vue component renders it.
Installation
Backend (Laravel / PHP 8.4+)
composer require givanov95/laravel-data-table
The service provider is auto-discovered. Publish the config if you want to customise the request parameter keys:
php artisan vendor:publish --tag=data-table-config
This creates config/data-table.php.
Frontend (Vue 3 + Inertia)
npm install @givanov95/vue-data-table
Register the plugin once (e.g. in app.ts / app.js). Both options are
optional — without them the components fall back to identity translations and
a global route() helper if one exists.
import { createApp } from "vue"; import { DataTablePlugin } from "@givanov95/vue-data-table"; createApp(App) .use(DataTablePlugin, { // Hook up your i18n helper: translator: (key) => window.__(key), // Hook up ziggy or whatever produces URLs: route: window.route, // Optional: debounce delay for filter/search reloads (ms) reloadDebounceMs: 1200, }) .mount("#app");
Configuration
config/data-table.php:
return [ 'translatable_table' => 'translations', 'translatable_column' => 'key', 'global_filter' => 'filter.global', 'per_page' => 'perPage', 'trashed' => 'filter.trashed', 'restore_id' => 'restore_id', 'ordering' => 'ordering', 'default_per_page' => 15, ];
These keys map directly to the HTTP query parameters the frontend sends.
Backend usage
Basic example
use Givanov95\DataTable\DataTable; use App\Models\User; public function index() { $table = (new DataTable(User::query())) ->setColumn('id', '#', searchable: true, orderable: true) ->setColumn('name', __('Name'), searchable: true, orderable: true) ->setColumn('email', __('Email'), searchable: true, orderable: true) ->setColumn('action', __('Action')) ->process(); return Inertia::render('Users/Index', [ 'dataTable' => fn () => $table, ]); }
setColumn accepts both shorthand positional arguments and a fully
constructed Column object — pick whichever reads better:
use Givanov95\DataTable\Columns\Column; $table ->setColumn(new Column('id', '#', searchable: true, orderable: true)) ->setColumn('action', __('Action'));
Relation columns
use Givanov95\DataTable\Columns\RelationColumn; $table->setRelationColumn( new RelationColumn('user.name', __('User'), searchable: true, orderable: true) );
Translatable columns
Designed to plug into the common translations morphMany pattern
(translatable_id, translatable_type, locale, key, text):
use Givanov95\DataTable\Columns\TranslatableColumn; $table->setTranslatableColumn( new TranslatableColumn( locale: app()->getLocale(), translationKey: 'title', label: __('Title'), searchable: true, orderable: true, ) );
Special column types
// Enum filtering by case name $table->setEnumColumn('status', App\Enums\OrderStatus::class); // Numeric-only filtering (currency / numeric input) $table->setPriceColumn('price'); // Date filtering with timezone-aware parsing $table->setDateColumn('created_at', 'd.m.Y H:i:s');
Eager-loading relations
$table->setRelation('translations'); $table->setRelation('user', ['id', 'name']);
Custom query hooks
$table->process(null, function ($query) { $query->where('owner_id', auth()->id()); }); // Or for free-form mutations: $table->advancedSearch(fn ($q) => $q->whereJsonContains('tags', 'featured'));
Frontend usage
<script setup lang="ts"> import { DataTable } from "@givanov95/vue-data-table"; import type { DataTableType } from "@givanov95/vue-data-table"; defineProps<{ dataTable: DataTableType<{ id: number; name: string; email: string }>; }>(); </script> <template> <DataTable :data-table="dataTable" :global-search="true" :per-page-options="[15, 30, 50]" > <template #cell(action)="{ item }"> <a :href="`/users/${item.id}/edit`">Edit</a> </template> </DataTable> </template>
Component props
| Prop | Type | Description |
|---|---|---|
dataTable |
DataTableType<T> |
The payload returned by (new DataTable(...))->process() |
propName |
string (default dataTable) |
Inertia prop key for partial reloads |
globalSearch |
boolean |
Show the global search input |
showTrashed |
boolean |
Show the "trashed" toggle |
advancedFilters |
boolean |
Reserve space for the advanced-filters slot |
selectedRowIndexes |
(string | number)[] |
Highlight matching rows |
selectedRowColumn |
string |
Column to match against selectedRowIndexes |
rowClickLink |
string |
URL template (use ?id placeholder) for row clicks |
perPageOptions |
number[] |
Render a per-page dropdown |
Slots
#additionalContent— content inside the toolbar (e.g. "Create" buttons)#advancedFilters— content inside the advanced-filters toolbar slot#cell(<column-key>)— custom renderer for a column; receives{ value, item }#cell(<relation.column>)— custom renderer for relation columns
Backend API reference
DataTable
__construct(Builder $builder, ?Request $request = null)setColumn(string|Column $keyOrColumn, ?string $label = null, bool $searchable = false, bool $orderable = false, bool $exactMatch = false): selfsetRelationColumn(RelationColumn $column): selfsetTranslatableColumn(TranslatableColumn $column): selfsetEnumColumn(string $key, class-string<\BackedEnum> $enumClass): selfsetPriceColumn(string $key): selfsetDateColumn(string $key, string $format, string $dateDelimiter = '.', string $timeDelimiter = ':'): selfsetRelation(string $relationString, ?array $columnsToSelect = null): selfsetOrdering(Ordering $ordering): selfsetRawOrdering(?RawOrdering $rawOrdering): selfprocess(?DataTableParams $params = null, ?callable $callbackBeforePaginate = null): selfadvancedSearch(callable $callback): selfgetData(): CollectiongetPaginator(): PaginatorgetBuilder(): BuildergetColumnByKey(string $key): ?Column
Column classes
| Class | Purpose |
|---|---|
Column |
Plain column (key, label, searchable, orderable…) |
RelationColumn |
Dot-notated relation column ('user.name') |
TranslatableColumn |
Pulls value from the configured translations table |
EnumColumn |
Internal — registered via setEnumColumn |
PriceColumn |
Internal — registered via setPriceColumn |
DateColumn |
Internal — registered via setDateColumn |
Repository layout
laravel-data-table/
├── composer.json # PHP package manifest
├── package.json # NPM package manifest
├── tsconfig.json
├── src/ # PHP source
│ ├── DataTable.php
│ ├── DataTableConfig.php
│ ├── DataTableParams.php
│ ├── DataTableServiceProvider.php
│ ├── ColumnFilter.php
│ ├── Columns/
│ ├── Exceptions/
│ ├── Support/
│ └── config/data-table.php
└── resources/
└── js/ # Vue / TypeScript source
├── index.ts
├── install.ts
├── config.ts
├── Table.vue
├── components/
├── icons/
├── types/
└── utils/
License
MIT
givanov95/laravel-data-table 适用场景与选型建议
givanov95/laravel-data-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「datatable」 「vue」 「inertia」 「data-table」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 givanov95/laravel-data-table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 givanov95/laravel-data-table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 givanov95/laravel-data-table 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.
Plug-ins for DataTables
A component that allows creating responsive HTML tables or lists from data object
Data Table will allow you to easily create Listing, Searching, Sorting and Download CSV.
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
crud widgets for laravel, to make an admin in few lines of code
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-26