PHPackages                             rougin/gable - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rougin/gable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rougin/gable
============

A simple HTML table generator in PHP.

v0.1.1(1w ago)01.1kMITPHPPHP &gt;=5.3.0CI passing

Since May 16Pushed 1mo agoCompare

[ Source](https://github.com/rougin/gable)[ Packagist](https://packagist.org/packages/rougin/gable)[ Docs](https://github.com/rougin/gable)[ RSS](/packages/rougin-gable/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Gable
=====

[](#gable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6f91f0c97de7ae498239a4616e64abc0da77d1f91562574bfcdc3d622db4c214/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f7567696e2f6761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/gable)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/rougin/gable/blob/master/LICENSE.md)[![Build Status](https://camo.githubusercontent.com/0e8cdd427719aad0c0d15a3934ff4fda4a939fb6a319f1b1d1e78da1e8a5b452/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f7567696e2f6761626c652f6275696c642e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/rougin/gable/actions)[![Coverage Status](https://camo.githubusercontent.com/9d8e813aed12fc21124f51b989e3bc0b53b8cfdc13255f2f9a19da35ac9fcef7/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f7567696e2f6761626c653f7374796c653d666c61742d737175617265)](https://app.codecov.io/gh/rougin/gable)[![Total Downloads](https://camo.githubusercontent.com/7664c64d3e146fd013fae36434a5002630d87db4e31af5da7f6a887f1a618871/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f7567696e2f6761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/gable)

A simple HTML table generator in PHP.

```
use Rougin\Gable\Table;

$table = new Table;

$table->newColumn();
$table->setCell('Name');
$table->setCell('Age');

$table->newRow();
$table->setCell('John Doe');
$table->setCell('30');

$table->newRow();
$table->setCell('Jane Doe');
$table->setCell('28');
```

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

[](#installation)

Install the package using [Composer](https://getcomposer.org/):

```
$ composer require rougin/gable
```

Basic usage
-----------

[](#basic-usage)

Use the `Table` class for generating HTML tables:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

// Define the table columns ---
$table->newColumn();
$table->setCell('Name');
$table->setCell('Age');
// ----------------------------

// Populate the table with data ---
$table->newRow();
$table->setCell('John Doe');
$table->setCell('30');

$table->newRow();
$table->setCell('Jane Doe');
$table->setCell('28');
// --------------------------------

echo $table->__toString();
```

The code above will generate the following HTML output:

```

    Name
    Age

    John Doe
    30

    Jane Doe
    28

```

Method chaining
---------------

[](#method-chaining)

Using method chaining is recommended for a fluent and expressive way of building tables:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

echo $table->newColumn()
  ->setCell('Name')
  ->setCell('Age')
  ->newRow()
  ->setCell('John Doe')
  ->setCell('30')
  ->newRow()
  ->setCell('Jane Doe')
  ->setCell('28');
```

Customization
-------------

[](#customization)

The appearance of the table can be customized by adding CSS classes, inline styles, and other attributes to columns, rows, and cells:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

// Adds CSS classes to the  element ---
$table->setClass('table table-striped');
// ------------------------------------------

// Adds a CSS class to the  row ---
$table->newColumn('fw-bold');
// --------------------------------------

// Aligns to center then adds a CSS class to the cell ---
$table->setCell('Name', 'center', 'text-uppercase');
// ------------------------------------------------------

// Aligns cell to the right ----
$table->setCell('Age', 'right');
// -----------------------------

// Adds a CSS class to the  element ---
$table->newRow('table-primary');
// ----------------------------------------

$table->setCell('John Doe');
$table->setCell('30');

$table->newRow();

// Adds a CSS class to the current cell --------
$table->setCell('Jane Doe', null, 'fst-italic');
// ---------------------------------------------

$table->setCell('28');

echo $table;
```

```

      Name
      Age

      John Doe
      30

      Jane Doe
      28

```

Pagination
----------

[](#pagination)

The `Pagee` class provides a simple way to generate pagination links for a table:

```
// index.php

use Rougin\Gable\Pagee;

$pagee = new Pagee;

$pagee->setTotal(100); // Total number of items
$pagee->setLimit(10); // Items per page
$pagee->setPage(2); // Current page
$pagee->setLink('/users'); // Base URL for the links

echo $pagee;
```

```

        First

        Previous

        1

        2

        3

        4

        5

        6

        7

        8

        9

        10

        Next

        Last

```

Using `alpinejs`
----------------

[](#using-alpinejs)

For creating dynamic and interactive tables, `Gable` provides a seamless integration with [alpinejs](https://alpinejs.dev/). This allows for features like real-time data updates, loading indicators, and more:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

// Sets the table with "users" for "alpinejs" ---
$table->withAlpine('users');
// ----------------------------------------------

// Shows a loading indicator while data is being fetched ---
$table->withLoading();
// ---------------------------------------------------------

$table->newColumn();
$table->setCell('Name')->withName('name');
$table->setCell('Email')->withName('email');

echo $table;
```

This will generate a table that is bound to an `alpinejs` component, ready to display dynamic data:

```

      Name
      Email

        No items found.

        An error occured in getting the items.

```

Actions
-------

[](#actions)

Actions can be added to each row, allowing for operations like updating or deleting records. The `withUpdateAction` and `withDeleteAction` methods provide a convenient way to add the specified common actions:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

$table->newColumn();
$table->setCell('Name');
$table->setCell('Age');

// Adds an "Action" column ---
$table->withActions();
// ---------------------------

$table->withUpdateAction('https://roug.in/update');
$table->withDeleteAction('https://roug.in/delete');

$table->newRow();
$table->setCell('John Doe');
$table->setCell('30');

$table->newRow();
$table->setCell('Jane Doe');
$table->setCell('28');

echo $table;
```

```

      Name
      Age
      Action

      John Doe
      30

          Action

            Update

            Delete

      Jane Doe
      28

          Action

            Update

            Delete

```

If `withAlpine` is defined, each action is defined by `@click` attribute instead of `href`:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

// Uses "alpinejs" to the table ---
$table->withAlpine();
// --------------------------------

$table->newColumn();
$table->setCell('Name');
$table->setCell('Age');

// Adds an "Action" column ---
$table->withActions();
// ---------------------------

// Methods will be used instead of links ---
$table->withUpdateAction('update(item.id)');
$table->withDeleteAction('delete(item.id)');
// -----------------------------------------

echo $table;
```

```

      Name
      Age
      Action

              Action

                  Update

                  Delete

```

Badges
------

[](#badges)

Badges can be used to highlight certain information in a cell, such as a record's status:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

$table->newColumn();

// Set the entire cell for badges ------
$table->setCell('Status')
    ->addBadge('Active', 'bg-success')
    ->addBadge('Inactive', 'bg-danger');
// -------------------------------------

$table->setCell('Name');
$table->setCell('Age');

$table->newRow();

// Specify the name of the badge ---
$table->useBadge('Active');
// ---------------------------------

$table->setCell('John Doe');
$table->setCell('30');

$table->newRow();
$table->useBadge('Inactive');
$table->setCell('Jane Doe');
$table->setCell('28');

echo $table;
```

```

      Name
      Age
      Action

        Active

      John Doe
      30

        Inactive

      Jane Doe
      28

```

If `withAlpine` is defined, add a state in each badge in the third argument:

```
// index.php

use Rougin\Gable\Table;

$table = new Table;

// Requires "alpinejs" to be enabled ---
$table->withAlpine();
// -------------------------------------

$table->newColumn();
$table->setCell('Status')
  ->addBadge('Active', 'bg-success', "item.status === 'active'")
  ->addBadge('Inactive', 'bg-danger', "item.status === 'inactive'");
$table->setCell('Name');
$table->setCell('Age');

echo $table;
```

```

      Status
      Name
      Age

              Active

              Inactive

```

Available methods
-----------------

[](#available-methods)

The following methods are available in the `Table` class:

```
/**
 * Adds a one-line custom HTML to the last added cell.
 *
 * @param string $html
 *
 * @return self
 */
public function addHtml($html)
```

```
/**
 * Adds a new "" element to the "".
 *
 * @param string|null  $class
 * @param string|null  $style
 * @param integer|null $width
 *
 * @return self
 */
public function newColumn($class = null, $style = null, $width = null)
```

```
/**
 * Adds a new "" element to the "".
 *
 * @param string|null  $class
 * @param string|null  $style
 * @param integer|null $width
 *
 * @return self
 */
public function newRow($class = null, $style = null, $width = null)
```

```
/**
 * Adds a new "" element.
 *
 * @param mixed|null   $value
 * @param string|null  $align
 * @param string|null  $class
 * @param integer|null $cspan
 * @param integer|null $rspan
 * @param string|null  $style
 * @param integer|null $width
 *
 * @return self
 */
public function setCell($value, $align = null, $class = null, $cspan = null, $rspan = null, $style = null, $width = null)
```

```
/**
 * Adds a column for action buttons.
 *
 * @param mixed|null   $value
 * @param string|null  $align
 * @param string|null  $class
 * @param integer|null $cspan
 * @param integer|null $rspan
 * @param string|null  $style
 * @param integer|null $width
 *
 * @return self
 */
public function withActions($value = 'Action', $align = null, $class = null, $cspan = null, $rspan = null, $style = null, $width = null)
```

```
/**
 * Enables usage of "alpine.js" in the table.
 *
 * @param string       $name
 * @param string|null  $class
 * @param string|null  $style
 * @param integer|null $width
 *
 * @return self
 */
public function withAlpine($name = 'items', $class = null, $style = null, $width = null)
```

```
/**
 * Adds a "Delete" action button.
 *
 * @param string $action
 * @param string $name
 *
 * @return self
 */
public function withDeleteAction($action, $name = 'Delete')
```

```
/**
 * Adds a loading indicator to the table.
 *
 * @param integer $count
 * @param string  $name
 *
 * @return self
 */
public function withLoading($count = 5, $name = 'loading')
```

```
/**
 * Adds an "Update" action button.
 *
 * @param string $action
 * @param string $name
 *
 * @return self
 */
public function withUpdateAction($action, $name = 'Update')
```

```
/**
 * Sets the text to display when there are no items in the table.
 *
 * @param string $text
 * @param string $key
 *
 * @return self
 */
public function withEmptyText($text, $key = 'empty')
```

```
/**
 * Sets the text to display when an error occurs while loading items.
 *
 * @param string $text
 * @param string $key
 *
 * @return self
 */
public function withErrorText($text, $key = 'loadError')
```

```
/**
 * Sets a name identifier to the last column cell.
 *
 * @param string $name
 *
 * @return self
 */
public function withName($name)
```

Styling per cell
----------------

[](#styling-per-cell)

The following fluent methods set attributes on the last added cell. They work for both column headers (``) and row cells (``):

```
$table = new Table;
$table->newColumn();

$table->setCell('Name')
    ->withAlign('center')
    ->withClass('text-uppercase')
    ->withWidth(30);

$table->newRow();
$table->setCell('John Doe')
    ->withStyle('color: red');

echo $table;
```

See the following methods that are available for styling:

```
/**
 * Sets the alignment of the last cell.
 *
 * @param string $align
 *
 * @return self
 */
public function withAlign($align)
```

```
/**
 * Sets the CSS class of the last cell.
 *
 * @param string $class
 *
 * @return self
 */
public function withClass($class)
```

```
/**
 * Sets the colspan of the last cell.
 *
 * @param integer $cspan
 *
 * @return self
 */
public function withCspan($cspan)
```

```
/**
 * Sets the rowspan of the last cell.
 *
 * @param integer $rspan
 *
 * @return self
 */
public function withRspan($rspan)
```

```
/**
 * Sets the inline CSS style of the last cell.
 *
 * @param string $style
 *
 * @return self
 */
public function withStyle($style)
```

```
/**
 * Sets the width of the last cell in percentage.
 *
 * @param integer $width
 *
 * @return self
 */
public function withWidth($width)
```

Restyling table
---------------

[](#restyling-table)

The default styling uses Bootstrap 5 classes. To use a different CSS framework, implement the `StyleInterface` and pass it to the table or any of its components:

```
namespace Rougin\Test\Styles;

use Rougin\Gable\StyleInterface;

class TailwindStyle implements StyleInterface
{
    public function badge()
    {
        return 'inline-flex items-center rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset';
    }

    public function dropdown()
    {
        return 'relative inline-block text-left';
    }

    public function dropdownButton()
    {
        return 'inline-flex w-full justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50';
    }

    public function dropdownDanger()
    {
        return 'text-red-600';
    }

    public function dropdownDivider()
    {
        return 'divide-y divide-gray-100';
    }

    public function dropdownItem()
    {
        return 'block px-4 py-2 text-sm text-gray-700';
    }

    public function dropdownMenu()
    {
        return 'absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5';
    }

    public function emptyCell()
    {
        return 'px-3 py-4 text-center text-sm text-gray-500';
    }

    public function loadingCell()
    {
        return 'px-3 py-4 animate-pulse';
    }

    public function loadingSpan()
    {
        return 'block h-4 w-full rounded bg-gray-200';
    }

    public function paginationActive()
    {
        return 'bg-indigo-600 text-white';
    }

    public function paginationDisabled()
    {
        return 'text-gray-400 cursor-not-allowed';
    }

    public function paginationItem()
    {
        return 'relative inline-flex items-center px-4 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50';
    }

    public function paginationLink()
    {
        return 'block';
    }

    public function paginationList()
    {
        return 'isolate inline-flex -space-x-px rounded-md shadow-sm';
    }

    public function paginationWrapper()
    {
        return 'flex items-center justify-center';
    }
}
```

```
use Rougin\Gable\Pagee;
use Rougin\Gable\Table;
use Rougin\Test\Styles\TailwindStyle;

$table = new Table;

// Apply the custom style to a table ---
$table->useStyle(new TailwindStyle);
// -------------------------------------

// Or apply to a specified element ---
$pagee = new Pagee;

$pagee->useStyle(new TailwindStyle);
// -----------------------------------
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/rougin/gable/blob/master/CHANGELOG.md) for more recent changes.

Contributing
------------

[](#contributing)

See [CONTRIBUTING](CONTRIBUTING.md) on how to contribute.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](https://github.com/rougin/gable/blob/master/LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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.

###  Release Activity

Cadence

Every ~35 days

Total

2

Last Release

12d ago

### Community

Maintainers

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

---

Top Contributors

[![rougin](https://avatars.githubusercontent.com/u/6078637?v=4)](https://github.com/rougin "rougin (46 commits)")

---

Tags

html-tablesphp-htmlphp-tablesphp-htmlhtml-tablesphp-tables

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rougin-gable/health.svg)

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

###  Alternatives

[monzer/filament-chatify-integration

Seamlessly integrate real-time messaging into your application.

265.3k](/packages/monzer-filament-chatify-integration)[aksw/rdfauthor

RDFauthor creates formular widgets out of RDFa-enhanced webpages.

198.8k1](/packages/aksw-rdfauthor)

PHPackages © 2026

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