86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
||
|
||
ini_set("display_errors", true);
|
||
error_reporting(-1);
|
||
|
||
require_once "../vendor/autoload.php";
|
||
|
||
use Itguild\Tables\Filter\InputDateFilter;
|
||
use Itguild\Tables\Filter\InputTextFilter;
|
||
use Itguild\Tables\Filter\SelectFilter;
|
||
use Itguild\Tables\ListJsonTable;
|
||
|
||
$json = file_get_contents('simple.json');
|
||
$table = new ListJsonTable($json);
|
||
|
||
$table->columns([
|
||
"created_at" => [
|
||
"format" => "date:Y-m-d",
|
||
'filter' => [
|
||
'class' => InputDateFilter::class,
|
||
]
|
||
],
|
||
'description' => [
|
||
"format" => "html",
|
||
"style" => ["width" => "300px"],
|
||
"filter" => [
|
||
'class' => InputTextFilter::class,
|
||
'value' => 'value'
|
||
],
|
||
"value" => function ($cell) {
|
||
return "<span style='color: sienna'>$cell</span>";
|
||
}
|
||
],
|
||
'description2' => [
|
||
"format" => "html",
|
||
"filter" => [
|
||
'class' => SelectFilter::class,
|
||
'param' => ['black', 'red', 'green', 'blue', 'yellow'],
|
||
'value' => 'red'
|
||
],
|
||
],
|
||
'status' => [
|
||
"filter" => [
|
||
'class' => SelectFilter::class,
|
||
'param' => getStatusLabel(),
|
||
'value' => 'Активный'
|
||
],
|
||
"value" => function ($cell) {
|
||
return getStatusLabel()[$cell];
|
||
}],
|
||
'k33' => [
|
||
"format" => "integer",
|
||
'filter' => [
|
||
'class' => \Itguild\Tables\Filter\InputRangeFilter::class,
|
||
'param' => ['min' => 0, 'max' => 10],
|
||
]
|
||
],
|
||
'email' => function ($cell) {
|
||
return "<span style='color: aqua'>$cell</span>";
|
||
},
|
||
]);
|
||
$table->afterPrint(function ($meta) {
|
||
return "<div>After Print</div>";
|
||
});
|
||
$table->addColumn("Колонка 33", "k33", function ($id) {
|
||
return "my ID: " . $id;
|
||
});
|
||
$table->addColumn("Колонка 34", "k34", function ($id) {
|
||
return "some34";
|
||
});
|
||
$table->addAction(function($row, $url){
|
||
return "<a href='mailto:". $row['email'] ."'>Написать</a>";
|
||
});
|
||
$table->create();
|
||
$table->render();
|
||
|
||
|
||
function getStatusLabel(): array
|
||
{
|
||
return [
|
||
0 => "На модерации",
|
||
1 => "Активный",
|
||
2 => "Модератор",
|
||
99 => "Удален",
|
||
];
|
||
} |