mindy / table
1.0.1
2016-04-29 14:37 UTC
Requires
- php: >=5.4
This package is not auto-updated.
Last update: 2024-09-14 15:47:41 UTC
README
该仓库是 django-tables2
的 PHP 克隆。
使用示例
<?php namespace Modules\Example\Tables; use Mindy\Table\Columns\RawColumn; use Mindy\Table\Table; use Modules\Example\ExampleModule; class ExampleDataTable extends Table { public function getColumns() { return [ 'created_at' => [ 'class' => RawColumn::className(), 'title' => CoreModule::t('Created at') ], 'message' => [ 'class' => RawColumn::className(), 'title' => CoreModule::t('Message') ], 'ip' => [ 'class' => RawColumn::className(), 'title' => CoreModule::t('Ip') ], 'username', 'url' ]; } }
在控制器中使用
... public function actionIndex() { $qs = ExampleData::objects(); $table = new ExampleDataTable($qs, [ 'paginationConfig' => [ 'pageSize' => 20 ] ]); echo $this->render('example/index.html', [ 'table' => $table ]); } ... Шаблон: ```twig {{ table|safe }} или {{ table.render()|safe }}
列(Columns)
当前版本仅实现了 3 个 Column
类。
TemplateColumn
- 使用示例
... 'foo' => [ 'class' => '\Mindy\Table\Columns\TemplateColumn', 'template' => 'my_app/my_template.html', 'title' => 'Super title' ] ...
传递给模板的参数
... 'value' => $value, // Значение 'record' => $record, // Модель 'table' => $table // Таблица ...
NumberColumn
- 使用示例
... 'foo' => [ 'class' => '\Mindy\Table\Columns\NumberColumn', 'decimals' => 2, 'decPoint' => '.', 'thousandsSep' => ',', 'title' => 'Super title' ] ...
RawColumn
- 使用示例
... 'foo' => [ 'class' => '\Mindy\Table\Columns\RawColumn', 'title' => 'Super title' ] ...