Download the PHP package ramondev/html-table-builder without Composer
On this page you can find all versions of the php package ramondev/html-table-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ramondev/html-table-builder
More information about ramondev/html-table-builder
Files in ramondev/html-table-builder
Package html-table-builder
Short Description Builds and renders an HTML table from an array or Eloquent collection
License MIT
Informations about the package html-table-builder
HTML Table Builder
Build and render HTML tables from an array or Eloquent collection, with dynamic columns, per-cell formatting, custom HTML attributes, output escaping, pagination, and an empty state — all from plain PHP, no Blade component boilerplate required in your own app.
Requirements
- PHP ^8.0.2
- Laravel 9 – 13 (
illuminate/support,illuminate/database,illuminate/view)
Installation
The service provider (Ramondev\HtmlTableBuilder\HTMLTableBuilderProvider)
auto-registers via Laravel's package discovery — no manual step needed. It
registers the package's Blade view under the views:: namespace, so the
view file ships with the package rather than living in your app's
resources/views.
Quick start
By default this renders every key found across the rows as a column, with values HTML-escaped.
Constructing a table
$data can be:
- A plain array of associative arrays (one per row), e.g.
[['id' => 1, 'name' => 'Ada'], ...] - An
Illuminate\Database\Eloquent\Collection— converted to an array automatically
Columns are auto-detected as the union of all keys found across every row.
Columns
Each column is either:
- A plain string key:
'name'— used as both the data key and the header label - A
[key, label]pair:['name', 'Full Name']— key looks up the value, label is shown in the header
setColumns(array $columns): void
Replace the column list entirely.
appendColumn(array $columns): void
Add columns to the end of the existing list.
removeColumns(array $columns): void
Remove columns by key.
tableHeadFormat(callable $callback): void
Transform every column's label (not its key) through a callback.
Cell values
columnFormat(string $key, callable $callback): void
Override the rendered value of a column for every row. The callback receives the original row (as an object) and its index.
If the callback returns HTML (e.g. a badge <span>), pair it with
escapeOutput(false, 'status') below — otherwise the markup renders as
literal text.
each(callable $callback): void
Iterate the raw source data, with $this (the table) passed in so the
callback can configure things per row.
Output escaping
Values are HTML-escaped by default.
escapeOutput(bool $escape, string|array|null $key = null): void
Calling with no $key sets the global default and clears any earlier
per-column overrides. Calling with a key (or array of keys) only touches
those columns.
Only disable escaping for values you control or have already sanitized — unescaped input renders as raw HTML/JS.
HTML attributes
Attribute values passed to any of these setters are automatically escaped.
Pagination
paginate(int $perPage, ?int $page = null): void
Enable pagination. If $page is omitted, the current page is read
automatically from the request's query string (?page=2 by default).
setPaginationPageName(string $name): void
Change the query string key — useful when a page has more than one paginated table.
setPaginationLabels(string $previous, string $next): void
setPaginationWindow(int $onEachSide): void
How many page numbers show on each side of the current page before
collapsing into .... Default is 3, e.g. 1 ... 4 5 [6] 7 8 ... 12. Only
visible once there are enough total pages to need collapsing.
setPaginationNavAttr() / setPaginationListAttr() / setPaginationLinkAttr(array $attrs): void
HTML attributes for the <nav> wrapper, the <ul>, and every <a> link.
hidePaginationControls(): void
Rows are still sliced to the current page, but the built-in Previous/Next/ number UI isn't rendered.
getPaginationMeta(): array
Returns the pagination state so you can build a fully custom UI, typically
combined with hidePaginationControls().
Pagination reads/builds the query string via
request(), so it requires an active HTTP request — not intended for CLI/artisan contexts.
Empty state
emptyState(string $message, array $attrs = [], bool $escape = true): void
Configure the row shown when there is no data (or the current page is empty).
Full example
Notes / gotchas
setColumns,appendColumn, andremoveColumnsrebuild the internal row data immediately — call them beforecolumnFormat,setTableRowAttr, etc.columnFormatandeachindex into the source data by row index — keep row indices stable (avoid re-keying the data before passing it in).- Row/cell attribute keys for
setTableRowAttr/setTableDataAttrrefer to the original row index from the source data, not the position within the current pagination page. - With few total pages,
setPaginationWindow()won't visibly change anything — the page list only collapses once there are more pages than the window's threshold allows.
License
MIT — see LICENSE.
All versions of html-table-builder with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/view Version ^9.0|^10.0|^11.0|^12.0|^13.0