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. rougin/gable

ActiveLibrary

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

A simple HTML table generator in PHP.

0696PHPCI passing

Since Jan 14Pushed 4mo agoCompare

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

READMEChangelogDependenciesVersions (1)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)
```

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

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

21

—

LowBetter than 18% of packages

Maintenance52

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

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.

### 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 (36 commits)")

---

Tags

html-tablesphp-htmlphp-tables

### Embed Badge

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

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

PHPackages © 2026

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