Download the PHP package humweb/inertia-table without Composer
On this page you can find all versions of the php package humweb/inertia-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download humweb/inertia-table
More information about humweb/inertia-table
Files in humweb/inertia-table
Package inertia-table
Short Description This is my package inertia-table
License MIT
Homepage https://github.com/humweb/inertia-table
Informations about the package inertia-table
Inertia Table
Server-driven data tables for Laravel + Inertia.js + Vue 3. Define your columns, filters, sorts, and search on the backend — the frontend renders it all automatically with per-table partial reloads.
Installation
Publish the config (optional):
Quick Start
1. Define a Resource
A Resource declares your table's columns, filters, model, and query behavior:
2. Use in a Controller
Single table
Multiple tables on one page
Each table is a lazy closure, so when the frontend does a partial reload targeting one table (e.g. only: ['tables.members']), only that table's query runs — the other stays untouched.
3. Frontend (Vue 3)
Single table
Multiple tables
Using the composable directly
Backend API
Resource
Extend Humweb\Table\Resource to define a table. Required methods:
| Method | Returns | Purpose |
|---|---|---|
fields() |
FieldCollection |
Column definitions |
filters() |
FilterCollection |
Filter definitions (optional, defaults to empty) |
Key properties:
| Property | Type | Default | Purpose |
|---|---|---|---|
$model |
string |
— | Eloquent model class |
$defaultSort |
string\|Sort |
'id' |
Default sort column or Sort instance |
$with |
array |
[] |
Eager-loaded relationships |
$primaryKey |
string |
'id' |
Record identifier |
$parameters |
array |
[] |
Route parameters passed to custom filters |
Custom parameter filters
Define filter{StudlyKey}($value) methods on your resource. Parameters set via addParameter() auto-dispatch to these methods:
Custom global search
Override globalFilter() to replace the default OR-across-searchable-fields behavior:
Runtime transforms
Fields
All fields extend Humweb\Table\Fields\Field and use the make() static constructor.
Available field types
| Class | Component | Purpose |
|---|---|---|
ID |
id-field |
Primary key |
Text |
text-field |
Text column |
Textarea |
textarea-field |
Long text |
Number |
number-field |
Numeric |
Date |
date-field |
Date/datetime |
Boolean |
boolean-field |
True/false badge |
Badge |
badge-field |
Status badge with map |
Currency |
currency-field |
Formatted currency |
Percent |
percent-field |
Progress bar |
Image |
image-field |
Image thumbnail |
Avatar |
avatar-field |
Round avatar |
Link |
link-field |
Clickable link |
Relation |
relation-field |
Related model link |
Computed |
computed-field |
Server-computed value |
Actions |
action-field |
Row action buttons |
Field modifiers
Filters
All filters extend Humweb\Table\Filters\Filter.
| Class | Component | Purpose |
|---|---|---|
TextFilter |
text-filter |
Free text input |
SelectFilter |
select-filter |
Dropdown select |
BooleanFilter |
boolean-filter |
Yes/No/Any |
DateRangeFilter |
date-range-filter |
From/to date picker |
NumberRangeFilter |
number-range-filter |
Min/max number |
EnumFilter |
enum-filter |
Enum value select |
ScopeFilter |
scope-filter |
Named query scope |
RelationshipFilter |
relationship-filter |
Filter by related model |
EmptyNotEmptyFilter |
empty-filter |
Null/empty check |
TrashedFilter |
select-filter |
Soft delete filter |
Filter modifiers
Sort Strategies
Sorts implement Humweb\Table\Sorts\Sort and are passed to ->sortable():
| Class | Purpose | Example |
|---|---|---|
BasicSort |
Simple ORDER BY (default). Delegates to Power Joins for dotted paths. |
->sortable() |
PowerJoinSort |
Sort by a column on a related model via Power Joins. | ->sortable(new PowerJoinSort('author', 'name')) |
AggregateSort |
Sort by withCount, withSum, withAvg, etc. |
->sortable(new AggregateSort('orders', 'sum', 'total')) |
SubquerySort |
Sort by an arbitrary subquery (escape hatch). | ->sortable(new SubquerySort(fn ($q) => ...)) |
CallbackSort |
Sort via a custom callback. | ->sortable(new CallbackSort(fn ($q, $desc, $prop) => ...)) |
NullsLastSort |
Sort with NULLs always at the bottom. | ->sortable(new NullsLastSort()) |
Collection sorts (client-side on server)
For sorts that require fetching all records and sorting in PHP (e.g. computed values):
| Class | Purpose |
|---|---|
BasicCollectionSort |
Sort a collection with auto type detection |
CallbackCollectionSort |
Custom collection sort callback |
Query Pipeline
The Resource builds queries through a QueryPipeline of discrete QueryStage objects. The default pipeline runs these stages in order:
ApplyEagerLoads—$withrelationshipsApplyDefaultSort— fallback sort when no?sort=paramApplySorts— user-requested sort from?sort=paramApplyGlobalSearch—?search[global]=(OR across searchable fields)ApplyCustomFilters— parameter-basedfilter*()methodsApplySearch— per-column?search[name]=ApplyFilters—FilterCollectionapplication from?filters[status]=
Customizing the pipeline
Override pipeline() in your resource to add, replace, or reorder stages:
Creating custom stages
Implement QueryStage:
TableRequest
TableRequest wraps the HTTP request with table-key awareness. For the default key, params are unprefixed (?sort=name). For named keys, params are prefixed (?members.sort=name).
Multi-Table Response Macro
The ->table() macro on Inertia\Response supports two signatures:
Each table is registered as a lazy closure. On the initial page visit both resolve. On partial reloads (e.g. sorting/filtering), Inertia's only parameter ensures only the targeted table re-evaluates.
Frontend API
All frontend code lives in resources/js/components/Table/v2/.
useTable(key?, options?)
The core composable. Call it with a table key to bind to a specific table's data from the Inertia page props.
Options
| Option | Type | Default | Purpose |
|---|---|---|---|
debounceMs |
number |
250 |
Debounce delay for search/filter changes |
preserveScroll |
boolean |
true |
Preserve scroll position on reload |
additionalOnly |
string[] |
[] |
Extra Inertia only keys to include in partial reloads |
Return value
| Property | Type | Description |
|---|---|---|
key |
string |
Table identifier |
sort |
Ref<string \| null> |
Current sort (e.g. 'name' or '-name') |
page |
Ref<number> |
Current page |
perPage |
Ref<number> |
Items per page |
columns |
ComputedRef<TableColumn[]> |
All column definitions |
visibleColumns |
ComputedRef<TableColumn[]> |
Only visible columns |
filters |
ComputedRef<TableFilterItem[]> |
Filter definitions with values |
search |
ComputedRef<TableSearchMap> |
Search field state |
hasGlobalSearch |
ComputedRef<boolean> |
Whether global search is available |
records |
ComputedRef<T[]> |
Current records (client-sorted if applicable) |
pagination |
ComputedRef<PaginationData> |
Pagination metadata |
isLoading |
Ref<boolean> |
Request in-flight indicator |
Methods
| Method | Signature | Description |
|---|---|---|
handleSort |
(attribute: string) => void |
Cycle sort: null -> asc -> desc -> null |
updateFilter |
(key: string \| number, value: unknown) => void |
Set a filter value |
updateSearch |
(key: string, value: unknown) => void |
Set a column search value |
updateGlobalSearch |
(value: unknown) => void |
Set global search value |
enableSearch |
(key: string) => void |
Enable a column search field |
removeSearch |
(key: string) => void |
Disable and clear a search field |
setPage |
(page: number) => void |
Navigate to page |
setPerPage |
(perPage: number) => void |
Change per-page (resets to page 1) |
toggleColumnVisibility |
(attribute: string, visible: boolean) => void |
Show/hide a column |
refresh |
() => void |
Force reload this table |
<DataTable> Component
The main component. Initializes useTable and provides it to child components via provide('table').
Props
| Prop | Type | Default | Description |
|---|---|---|---|
tableKey |
string |
'default' |
Table key matching the backend |
enableRowSelection |
boolean |
false |
Show row checkboxes |
selectionKey |
string |
'id' |
Record property for selection identity |
hideToolbar |
boolean |
false |
Hide the toolbar |
caption |
string |
'' |
Accessible table caption |
ariaLabel |
string |
'' |
Accessible table label |
options |
UseTableOptions |
{} |
Options forwarded to useTable |
Slots
| Slot | Scope | Description |
|---|---|---|
toolbar |
{ table } |
Replace the entire toolbar |
table |
{ table, records } |
Replace the entire table element |
head |
{ columns, sortHandler, sort } |
Replace the <thead> |
body |
{ records, columns } |
Replace the <tbody> |
cell:{attribute} |
{ record, field } |
Override a specific column cell |
pagination |
{ table } |
Replace pagination |
Sub-components
All sub-components inject useTable via inject('table') and can be used standalone:
| Component | Purpose |
|---|---|
TableToolbar |
Search, filters, column visibility |
TableHeader / TableHeaderCell |
Sortable column headers |
TableBody / TableBodyCell |
Record rows with field rendering |
TablePagination |
Page navigation and per-page select |
FieldRenderer |
Resolves field component by component type |
FilterRenderer |
Resolves filter component by component type |
GlobalSearch |
Search input for global search |
ColumnSearch |
Active column search fields |
ColumnSearchDropdown |
Dropdown to enable column searches |
Imports
Configuration
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- ryun
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of inertia-table with dependencies
aaronfrancis/fast-paginate Version ^2.0
illuminate/contracts Version ^10.0||^11.0||^12.0
inertiajs/inertia-laravel Version ^2
kirschbaum-development/eloquent-power-joins Version ^4.2
spatie/laravel-package-tools Version ^1.19