PHPackages                             tjbp/tablelegs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. tjbp/tablelegs

ActiveLibrary[Templating &amp; Views](/categories/templating)

tjbp/tablelegs
==============

Easily create HTML tables with ordering, filtering and pagination.

2218PHP

Since Dec 28Pushed 10y ago1 watchersCompare

[ Source](https://github.com/tjbp/tablelegs)[ Packagist](https://packagist.org/packages/tjbp/tablelegs)[ RSS](/packages/tjbp-tablelegs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tablelegs
=========

[](#tablelegs)

[![StyleCI](https://camo.githubusercontent.com/8cd5730db5410a13ed9bb7c92702848d5cc779584c4762841a36c63a326f39f5/68747470733a2f2f7374796c6563692e696f2f7265706f732f34333834383037302f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/43848070)[![Build Status](https://camo.githubusercontent.com/4e56f89b0e91f7de0daede2e63bb736c7b5c973231b3a55f2b2f5fe78b765401/68747470733a2f2f7472617669732d63692e6f72672f746a62702f7461626c656c6567732e737667)](https://travis-ci.org/tjbp/tablelegs)[![Total Downloads](https://camo.githubusercontent.com/64f69eb26400f34f3e39b3477726effc5082b99e3f83c5ebd4b369cef8b23699/68747470733a2f2f706f7365722e707567782e6f72672f746a62702f7461626c656c6567732f642f746f74616c2e737667)](https://packagist.org/packages/tjbp/tablelegs)[![Latest Stable Version](https://camo.githubusercontent.com/25a8d694cd0dea4ab3fb2f4e6fddb5fafc3c43d617447297055ac604838619ae/68747470733a2f2f706f7365722e707567782e6f72672f746a62702f7461626c656c6567732f762f737461626c652e737667)](https://packagist.org/packages/tjbp/tablelegs)[![Latest Unstable Version](https://camo.githubusercontent.com/b3efb8887c46aef9b748ab3436cfca3d28e71ffefbd62f19e583ed8fe16d089c/68747470733a2f2f706f7365722e707567782e6f72672f746a62702f7461626c656c6567732f762f756e737461626c652e737667)](https://packagist.org/packages/tjbp/tablelegs)[![License](https://camo.githubusercontent.com/79eac2aedddc649496cffd59cc2829e98903f1215b20ec630a61d5fb52869145/68747470733a2f2f706f7365722e707567782e6f72672f746a62702f7461626c656c6567732f6c6963656e73652e737667)](https://packagist.org/packages/tjbp/tablelegs)

Tablelegs allows you to easily build an HTML table from a database, including support for filters, sortable columns and pagination. Tablelegs does not output HTML, it simply provides helpers for outputting a table according to a purpose-built class and can generate URLs for enabling filters and sorting.

Installation
------------

[](#installation)

Tablelegs is installable [with Composer via Packagist](https://packagist.org/packages/tjbp/tablelegs).

Usage
-----

[](#usage)

### Extend `Tablelegs\Table`

[](#extend-tablelegstable)

Each table should have its own class, though if you have tables with many similarities, you could easily create a base table with the common properties/methods and extend it for each table. Consider placing your all your table classes in a `Tables` namespace within your application.

The bare minimum required for a table is the `$columnHeaders` property. When instantiating your table class, simply pass it your database. Supported databases are simple associative arrays, a numeric array of associative arrays, a Laravel Collection, or a Laravel Eloquent builder. Supported databases are automatically detected.

You can support further databases by extending `Tablelegs\Databases\Database` and implementing `Tablelegs\Databases\DatabaseInterface`, then setting the `$dbClass` property of your table to its name.

Here is a simple example of a table class:

```
namespace App\Tables;

use Tablelegs\Table;

class ManageUsers extends Table
{
    public $columnHeaders = [
        'user_id' => 'User ID',
        'username' => 'Username',
        'email' => 'Email',
        'joined' => 'Joined',
        'last_login' => 'Last login',
    ];

    public $filters = [
        'Type' => [
            'Administrator',
            'Moderator',
        ],
    ];

    public $presenter = FoundationFivePresenter::class;

    public function filterTypeAdministrator()
    {
        return $this->db->where('administrator', true);
    }

    public function filterTypeSeller()
    {
        return $this->db->where('moderator', true);
    }
}
```

### Column headers

[](#column-headers)

Column headers are defined in the `$columnHeaders` property of a table class, with the URL-friendly name as the key, and the natural language equivalent as the value.

### Sorting

[](#sorting)

Tablelegs will allow sorting by any column and will attempt to do this itself. However the logic can be overriden using a method defined in the format `sortColumn`. The method will be passed the sort order (`"asc"` or `"desc"`) as its only argument.

### Filters

[](#filters)

Filters are defined in the `$filters` property of a table class, as a multi-dimensional array. The keys of the first level of the array represent the natural language name for your filter (the filter key). Values on the second level represent the options for a filter, again in natural language.

Each filter should have a counterpart method defined in the format `filterNameOption`. The method should contain logic that filters the class `$db` property appropriately. The example shown above is using Laravel's Eloquent querying system; if you were using an array database you might utilise `array_filter()` instead.

Note that in URLs, filter names and options are automatically lower-cased and spaces are replaced with underscores, largely for aesthetic reasons.

### Outputting the table (vanilla PHP)

[](#outputting-the-table-vanilla-php)

```

    :

```

### Outputting the table (Laravel 5)

[](#outputting-the-table-laravel-5)

Place a method in your controller:

```
public function getUsers()
{
    // This is the same table definition as in the example above
    $table = new ManageUsers(User::query());

    return view('manage.users', [
        'table' => $table,
        'users' => $table->paginate()
    ]);
}
```

You can use the `paginate()` method to paginate the results, or fetch the entire dataset with `get()`.

Views for use with Laravel's Blade templating system and [ZURB Foundation](http://foundation.zurb.com/) are also included, as used in the following example:

```
@include('tablelegs::filter')

    @include('tablelegs::header')

        @foreach ($users as $user)

                {{ $user->userId }}
                {!! u($user) !!}
                {{ $user->email }}
                {{ date('Y/m/d', $user->joined) }}
                {{ date('Y/m/d', $user->last_login) }}

        @endforeach

        {!! $table->paginator() !!}

```

### Licence

[](#licence)

Tablelegs is free and gratis software licensed under the [GPL3 licence](https://www.gnu.org/licenses/gpl-3.0).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d40eba324b455601b0d0c22f6e1a1454407ad5466ef1f6fd635f3f2b0a9e5e85?d=identicon)[tjbp](/maintainers/tjbp)

---

Top Contributors

[![tjbp](https://avatars.githubusercontent.com/u/2157634?v=4)](https://github.com/tjbp "tjbp (22 commits)")

### Embed Badge

![Health badge](/badges/tjbp-tablelegs/health.svg)

```
[![Health](https://phpackages.com/badges/tjbp-tablelegs/health.svg)](https://phpackages.com/packages/tjbp-tablelegs)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
