roarbb / datagrid
Datagrid is Data renderer with some configuration options
Requires
- guzzlehttp/guzzle: 5.0.*@dev
- latte/latte: ~2.2
- nette/utils: ~2.2
- phpmd/phpmd: @stable
- squizlabs/php_codesniffer: 2.*
- tracy/tracy: ~2.2
Requires (Dev)
- fzaninotto/faker: 1.5.*@dev
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2024-05-07 02:03:27 UTC
README
Datagrid is PHP component to creating tables from a set of data.
Live Example
Here: http://datagrid.sajgal.com.
Installation
The recommended way to install Datagrid is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | 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(); $datagrid->setData($data);
Then in template file:
<h1>Datagrid</h1> <?php echo $datagrid ?>
More Options
Json source
If you want to build table from valid JSON REST API response:
$datagrid->setDataUrl('http://datagrid.sajgal.com/?getJson');
Table html class attribute
If you are using Bootstrap you may need to set css class to Datagrid.
$datagrid->setTableClass('table');
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']);
Sorting
If you want to enable sorting of Datagrid rows
$datagrid->isSortable();
Hiding Columns
If you want to hide some of columns with sensitive content
$datagrid->hideColumns(['pin']);
Pagination
You can also enable pagination. You should pass rows per page integer as first argument.
$datagrid->setPagination(10);
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', 'http://datagrid.sajgal.com/delete/{name}');