lavdiu / php-grid
PHP Grid - 在PHP中轻松创建灵活的网格
1.1.0
2021-04-02 07:56 UTC
Requires
- php: >=7.2
- ext-json: *
- ext-pdo: *
- box/spout: ^3.1
- phpoffice/phpspreadsheet: ^1.14
Requires (Dev)
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2024-09-15 18:36:02 UTC
README
PHP Grid - 允许使用PHP和JS构建动态网格的简单PHP类
入门指南
先决条件
此类依赖于以下库
box/spout
和phpoffice/phpspreadsheet
以在服务器端生成Excel导出- SheetJS 在浏览器中生成Excel/CSV导出。
- JQuery 和
- Bootstrap 4
安装
要安装此库,请使用以下命令
composer require lavdiu/php-grid
将 grid.js
从 assets/
文件夹复制到您的资源文件夹或Web目录的根目录,并在您的页面中包含它。
用法
require_once __DIR__ . '/../vendor/autoload.php'; use PhpGrid\PhpGrid; use PhpGrid\Column; use PhpGrid\ActionButton; $pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password'); $grid = new PhpGrid($pdo, 'contacts_list'); $grid->setTitle('List of all contacts') ->setRowsPerPage(10) ->setSqlQuery("SELECT id, name, email, created_on FROM contact_list") ->addColumn(new Column('id', 'Contact Id', true, true, '?mod=contact&id={id}', '_blank')) ->addColumn(new Column('email', 'Email Address')) ->addActionButton(new ActionButton('View', '?mod=contact&id={id}', 'fa fa-eye')) ->addActionButton(new ActionButton('Update', '?mod=contact&id={id}&action=update', 'fa fa-pencil')); /** * Setting custom attributes to the button */ $deleteButton = new ActionButton('Delete', '?mod=contact&id={id}&action=delete', 'fa fa-trash'); $deleteButton->addAttribute('onclick', "return confirm('Are you sure?');"); $grid->addActionButton($deleteButton); /** * Set custom style/classes to the cell itself */ $col1 = new Column('name', 'Full Name'); $col1->setOuterElementCssClass('text-center'); $col1->setOuterElementCssStyle('background-color:silver'); $grid->addColumn($col1); /** * Set custom style/classes to the content of the cell */ $col2 = new Column('created_on', 'Registration Date', true); $col2->setInnerElementCssClass('border border-danger'); $col2->setInnerElementCssStyle('color:red;cursor:pointer;'); $grid->addColumn($col2); $grid->setDebug(true); #output additional debugging info in json responses if ($grid->isReadyToHandleRequests()) { $grid->bootstrap(); } echo $grid->draw();
有关更多示例,请参阅示例目录