Download the PHP package givanov95/laravel-data-table without Composer

On this page you can find all versions of the php package givanov95/laravel-data-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-data-table

Laravel DataTable

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 12–13 / PHP 8.3+)

The service provider is auto-discovered. Publish the config if you want to customise the request parameter keys:

This creates config/data-table.php.

Frontend (Vue 3 + Inertia)

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.


Configuration

config/data-table.php:

These keys map directly to the HTTP query parameters the frontend sends, and both DataTable and QueryBuilderTable read them (trashed only when the table calls allowTrashed()). ordering is the parameter that carries ordering[key] and ordering[direction]. The Vue components bundled with the package send the defaults above, so changing a key means pairing it with your own frontend.

The page size read from the request is bounded: anything above max_per_page is cut to it (so ?perPage=100000 cannot load the whole table), and anything that is not a number or is below 1 (empty, text, an array, zero, negative) falls back to default_per_page. default_per_page is capped by max_per_page too. This applies to both DataTable and QueryBuilderTable.


Backend usage

Basic example

Sorting requested by the client (ordering[key], ordering[direction]) is only applied to columns registered with orderable: true (for a RelationColumn, its relation.column path). Any other key is ignored and the default ordering (id DESC) is used. An ordering you set yourself with setOrdering(new Ordering(...)) is applied as-is.

setColumn accepts both shorthand positional arguments and a fully constructed Column object — pick whichever reads better:

Lightweight spatie table (QueryBuilderTable)

For lean listings that don't need the column-type system, QueryBuilderTable wraps spatie/laravel-query-builder and emits the same { data, meta, columns, state } contract, so the same frontend consumes it. It handles global search, sorting, the trashed toggle, a perPage cap, and an optional transform() for whitelisting output (keep PII out of the listing).

The request keys (search, trashed, ordering and per-page) come from config/data-table.php, like in DataTable. Spatie rejects a filter[...] it does not know with InvalidFilterQuery, so QueryBuilderTable accepts the filters named by the configured keys when they sit under Spatie's filter parameter ('global_filter' => 'filter.search' accepts filter[search]), and keeps tolerating filter[global], filter[timeZone] and (with allowTrashed()) filter[trashed]. A search key outside that parameter ('global_filter' => 'q') works too.

Filters by column take 'filter' in columns(): 'text' (contains), 'exact' (one or several values, never one the column cannot hold), 'select' (with 'options', as for setFilterOptions()) or 'date' (a range of calendar days, in the server's zone). They are applied by the table, not by Spatie, so filter[title]=Smith, John stays one value.

allowTrashed(ability: 'viewArchive') shows the soft-deleted rows only to users Gate::allows('viewArchive', User::class); for the rest, and for a model without SoftDeletes, the trashed toggle is accepted and ignored (no 400, no 500).

The page size is bounded by data-table.max_per_page (see Configuration); call ->maxPerPage(50) to override it for a single table (it throws InvalidArgumentException below 1). Without ?perPage the page size is data-table.default_per_page, like in DataTable; ->defaultPerPage(25) overrides it for a single table.

Use DataTable for column-rich tables; use QueryBuilderTable for lean listings that want spatie's query power behind a small, reusable facade.

Relation columns

Ordering joins each relation of the path, so an orderable relation column takes BelongsTo, HasOne and MorphOne relations (keys and morph class from the relation). Any other relation (HasMany, BelongsToMany, MorphTo, a …OfMany()) would repeat rows, so setRelationColumn() throws UnsupportedRelationException for an orderable column on it. A searchable-only column takes any relation (it is a whereHas).

Translatable columns

Designed to plug into the common translations morphMany pattern (translatable_id, translatable_type, locale, key, text). The relation and the key / locale / text columns are configurable (translatable_*); the table, the model's key and the morph class (a morph map alias, too) come from the relation. The translations the columns show are loaded with the page (only their keys and locales), unless the query already loads the relation (with('translations'), setRelation('translations')):

fallbackLocales lists languages tried in order when a row has no text (or an empty one) in locale, e.g. an admin list that also shows records not yet translated into the admin's language. Enums are taken as their value:

Special column types

The search box takes a date column as d.m.Y, d.m, H:i, H:i:s, d.m.Y H:i or d.m.Y H:i:s (with the column's delimiters). The composable sends the browser's time zone with the search (time_zone key), and for a column whose format has a time (H), what the user types is read in that zone:

The server's zone is app.timezone; the stored values are taken to be wall-clock times in it. A zone PHP does not know (a typo, or an old alias such as Europe/Kiev on some PHP builds) is ignored: the server's zone is used.

Supported databases

Date filtering formats the column in SQL, so it needs a driver-specific expression. It is supported on:

Database Driver SQL used
MySQL / MariaDB mysql, mariadb DATE_FORMAT(column, …)
PostgreSQL pgsql TO_CHAR(column, …)
SQLite sqlite strftime(…, column)

An exactMatch column (and an exact price) never hands the database a value its type rejects: PostgreSQL fails the whole query on id = 'abc', where MySQL and SQLite find nothing. A term the column cannot hold matches nothing; any other is the usual typed comparison, so results and indexes are unchanged.

On any other driver (e.g. SQL Server) filtering a date column throws Givanov95\DataTable\Exceptions\UnsupportedDriverException. The other filters (text, enum, price) are plain Eloquent where clauses and do not depend on it.

Eager-loading relations

Custom query hooks

Filters by column

A column declared filterable takes its own filter from the request, next to the search: filter[<key>] (the parameter is column_filters). The filters AND with each other and with the search. The kind of filter follows the column:

toArray() describes each column's filter (columns[].filterable, columns[].filter: {type: 'select', options: [{value, label}]}, {type: 'date'} or {type: 'text'}) and gives the applied ones in state.filters.

Archive and restore

The archive (soft-deleted rows) is off unless the table turns it on. Without allowTrashed(), filter[trashed]=true is ignored and the live rows are listed.

With an ability, users the gate refuses get the live rows (the parameter is ignored, not a 403). A model without SoftDeletes never shows an archive, so calling allowTrashed() on it is harmless. toArray()['state']['trashed'] (and $table->trashed in the default serialization) is what was applied, and state.trashed_allowed ($table->trashedAllowed) whether this user may see the archive at all: the bundled components show the archive toggle only then.

Restoring is a POST route of the app, never a query parameter of the list (a GET that changes data can be triggered from another site). Build the table the same way as for the list and call restore():

restore($id, $scope) looks the record up through the table's query and $scope (pass the same narrowing as the callback of process()), among the archived rows only, so a record the table does not list is a 404. It then checks the restore policy (authorize('restore', $record)), restores the record and redirects back with a success flash message. It is a 404 when the table has no allowTrashed() or the model has no SoftDeletes, and a 403 when the ability of allowTrashed() refuses.

The app's own rules go in $before, which runs after all those checks, with the record, right before it is restored. It can refuse by throwing, and attributes it sets are saved by the restore in the same write. restoreRecord() does the same and returns the record, leaving the response (and its message) to the app:

On the frontend, pass the route to the composable (restoreUrl) or to the DataTable component (restore-url); see below.


Frontend usage

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 (needs allowTrashed())
restoreUrl string POST URL (use ?id) of the restore button on archived rows; no button without it
rowKey string Field that fills ?id (default: the model's key from the payload, else id)
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


TanStack Table + shadcn-vue

For apps built on shadcn-vue (Laravel's Vue starter kit and the ones derived from it), the package has a second frontend: a composable that drives the payload of ->process()->toArray() with TanStack Table in manual mode, and a shadcn-vue UI for it.

The two parts are delivered the way each one has to be:

Part What How
Logic useLaravelDataTable() and the payload types npm: @givanov95/vue-data-table/tanstack — updated with npm update
UI ServerDataTable, DataTable, DataTableColumnHeader, features.ts published into the app — it imports the app's own @/components/ui/*

Install

The UI lands in resources/js/components/ui/data-table/. It needs these shadcn-vue components in the app: button, input, label, select, switch, table and dropdown-menu, and the @lucide/vue icons.

Update both together, so the UI and the composable stay on one version:

The published files are the package's: --force overwrites them. Change them here (props, slots) rather than in the app.

Texts

Every text of the UI goes through the package's translator, with the English text as the key. Hook up the app's translator once, after its own i18n plugin:

Without a translator the English keys are shown, with :placeholders filled in. The keys, for the app's lang/*.json:

Key bg nl
Search… Търсене… Zoeken…
No results. Няма резултати. Geen resultaten.
Show archived Покажи архивираните Toon gearchiveerde
Showing :from–:to of :total Показани :from–:to от :total :from–:to van :total
Rows per page Редове на страница Rijen per pagina
First page Първа страница Eerste pagina
Previous page Предишна страница Vorige pagina
Next page Следваща страница Volgende pagina
Last page Последна страница Laatste pagina
Columns Колони Kolommen
Clear filters Изчисти филтрите Filters wissen
No options Няма опции Geen opties
:label from :label от :label vanaf
:label to :label до :label tot

The translator receives :from, :to and :total as replacements; it must replace the longest names first (Laravel does), or :to eats the start of :total. fillPlaceholders() of the package does it right.

Usage

useLaravelDataTable(payload, options) options: propName (default dataTable), alsoReload (other props to refresh with the table, e.g. the page's own filters), searchDebounceMs (1200), perPageOptions ([10, 20, 50, 100]; the applied size is always offered) and restoreUrl ('/posts/?id/restore' or (id) => route('posts.restore', id)): onRestore(id, visitOptions?) POSTs there (with the page's own onSuccess / onError / onFinish, if given) and does nothing without it. restoringId holds the row being restored until its POST ends, so a button can show it; a second click meanwhile does nothing. trashedAllowed says whether the server allows this user the archive. The table follows the server's applied state (state.sort, state.search, state.trashed), so back/forward and shared links stay right; a new sort, page size, search or archive goes back to page 1. clearSearch(data) empties the search box and reloads once, together with the page's own filter changes. The request keys come from the payload's params (config/data-table.php), so changing a key there needs nothing on the frontend.

A RawOrdering hides the sort from state.sort (the rows are not in the order of a column then); pass what it amounts to when there is one: new RawOrdering('created_at DESC, id DESC', new Ordering('created_at', 'DESC')).

The filters by column come with the composable: filterColumns (the columns the server filters by, with their kind and options), filters (the values, as the server applied them), setColumnFilter(key, value) (a select or a date range is sent at once, a text waits like the search box; an empty value removes the filter), clearColumnFilters() and hasColumnFilters. Each change goes back to page 1. For TanStack, the same filters are state.columnFilters and onColumnFiltersChange.

ServerDataTable draws them in the toolbar, after the search box: a select is a button with the column's label that opens a list of checkboxes (and shows how many are ticked), a date range is two date fields with the column's label, and a text is a field. "Clear filters" shows while any filter is on. On a narrow screen the toolbar wraps and the date range takes its own line. :show-filters="false" leaves them out, to draw the page's own in #toolbar.

ServerDataTable props beyond the composable's: showTrashed, searchPlaceholder, emptyText, trashedLabel, cellClass (classes on every body cell, e.g. align-top for tall rows) and showFilters (true).

DataTable is the client-side counterpart for rows already in the page (no server round trip): search, sorting, column toggle and the same footer as ServerDataTable ("Showing 1–10 of 25", page numbers, per-page select). Props: columns, data, pageSize (10), pageSizeOptions ([10, 20, 50, 100], [] hides the select), enableGlobalFilter, enableColumnToggle, searchPlaceholder, emptyText, columnsLabel. Prefer ServerDataTable for anything that can grow: DataTable loads every row.


Backend API reference

DataTable

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

License

MIT


All versions of laravel-data-table with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/pagination Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
spatie/laravel-query-builder Version ^7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package givanov95/laravel-data-table contains the following files

Loading the files please wait ...