roarbb/datagrid
Composer 安装命令:
composer require roarbb/datagrid
包简介
Datagrid is Data renderer with some configuration options
关键字:
README 文档
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}');
统计信息
- 总下载量: 88
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-26