Skip to content
Datagrid renderer
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Datagrid is PHP component to creating tables from a set of data.

Live Example



The recommended way to install Datagrid is through Composer.

# Install Composer
curl -sS | php

Next, run the Composer command to install the latest stable version of Datagrid:

composer require roarbb/datagrid

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Basic usage

Let's have some array of data:

$data = array(
    'row1' => array(
        'name' => 'Tyree',
        'surname' => 'Schmidt',
        'age' => '35',
        'position' => 'Developer',
        'pin' => '7366',
    'row2' => array(
        'name' => 'Cleve',
        'surname' => 'Streich',
        'age' => '38',
        'position' => 'Management',
        'pin' => '7290',
    'row3' => array(
        'name' => 'Mossie',
        'surname' => 'Lesch',
        'age' => '41',
        'position' => 'Sales',
        'pin' => '6521',
    'row4' => array(
        'name' => 'Kayla',
        'surname' => 'Paucek',
        'age' => '21',
        'position' => 'Developer',
        'pin' => '9478',
    'row5' => array(
        'name' => 'Elva',
        'surname' => 'Haley',
        'age' => '17',
        'position' => 'Management',
        'pin' => '4532',

Basic implementation of Datagrid:

$datagrid = new Datagrid();

Then in template file:

<?php echo $datagrid ?>

More Options

Json source

If you want to build table from valid JSON REST API response:


Table html class attribute

If you are using Bootstrap you may need to set css class to Datagrid.


Header Row

You can set header row of Datagrid. Count of array elements passed as argument should match count of items in each row element of $data variable.

$datagrid->addHeader(['First name', 'Surname', 'Age', 'Position', 'PIN Code']);


If you want to enable sorting of Datagrid rows


Hiding Columns

If you want to hide some of columns with sensitive content



You can also enable pagination. You should pass rows per page integer as first argument.


Action Buttons

If you want to add some buttons at the end of each row. You can use placeholders: {name} will be translated to Tyree etc.

$datagrid->addAction('Delete Row', '{name}');
You can’t perform that action at this time.