tables/examples/simple.php

80 lines
2.0 KiB
PHP
Raw Normal View History

2024-05-27 12:59:44 +03:00
<?php
2024-07-30 12:20:16 +03:00
require_once "../vendor/autoload.php";
2024-05-27 12:59:44 +03:00
2024-08-28 15:39:35 +03:00
use Itguild\Tables\Filter\InputDateFilter;
use Itguild\Tables\Filter\InputTextFilter;
2024-08-28 14:21:00 +03:00
use Itguild\Tables\Filter\SelectFilter;
2024-05-27 12:59:44 +03:00
use Itguild\Tables\ListJsonTable;
$json = file_get_contents('simple.json');
$table = new ListJsonTable($json);
2024-08-01 15:10:41 +03:00
2024-08-06 12:10:26 +03:00
$table->columns([
2024-08-08 14:21:47 +03:00
"created_at" => [
2024-08-22 13:08:25 +03:00
"format" => "date:Y-m-d",
2024-08-28 14:21:00 +03:00
'filter' => [
2024-08-28 15:39:35 +03:00
'class' => InputDateFilter::class,
2024-08-28 14:21:00 +03:00
]
2024-08-08 14:21:47 +03:00
],
2024-08-08 17:08:46 +03:00
'description' => [
"format" => "html",
"style" => ["width" => "300px"],
2024-08-28 14:21:00 +03:00
"filter" => [
2024-08-28 15:39:35 +03:00
'class' => InputTextFilter::class,
2024-08-28 15:09:34 +03:00
'value' => 'value'
2024-08-28 14:21:00 +03:00
],
2024-08-08 17:08:46 +03:00
"value" => function ($cell) {
return "<span style='color: sienna'>$cell</span>";
}
2024-08-08 16:31:26 +03:00
],
2024-08-23 14:52:22 +03:00
'description2' => [
2024-08-28 14:21:00 +03:00
"format" => "html",
"filter" => [
'class' => SelectFilter::class,
2024-08-28 15:09:34 +03:00
'param' => ['black', 'red', 'green', 'blue', 'yellow'],
'value' => 'red'
2024-08-28 14:21:00 +03:00
],
2024-08-23 14:52:22 +03:00
],
2024-08-13 14:30:00 +03:00
'status' => [
2024-08-28 14:21:00 +03:00
"filter" => [
'class' => SelectFilter::class,
2024-08-28 15:09:34 +03:00
'param' => getStatusLabel(),
'value' => 'Активный'
2024-08-28 14:21:00 +03:00
],
2024-08-13 14:30:00 +03:00
"value" => function ($cell) {
return getStatusLabel()[$cell];
}],
2024-08-28 14:21:00 +03:00
'k33' => [
"format" => "integer",
'filter' => [
2024-08-28 15:39:35 +03:00
'class' => \Itguild\Tables\Filter\InputRangeFilter::class,
'param' => ['min' => 0, 'max' => 10],
2024-08-28 14:21:00 +03:00
]
],
2024-08-06 12:10:26 +03:00
'email' => function ($cell) {
return "<span style='color: aqua'>$cell</span>";
2024-08-01 15:10:41 +03:00
},
]);
2024-07-31 12:48:26 +03:00
$table->afterPrint(function ($meta) {
2024-07-30 12:20:16 +03:00
return "<div>After Print</div>";
});
2024-08-01 13:32:31 +03:00
$table->addColumn("Колонка 33", "k33", function ($id) {
2024-07-31 17:11:29 +03:00
return "my ID: " . $id;
});
2024-08-01 13:32:31 +03:00
$table->addColumn("Колонка 34", "k34", function ($id) {
2024-07-31 17:11:29 +03:00
return "some34";
});
2024-05-27 12:59:44 +03:00
$table->create();
2024-08-01 13:32:31 +03:00
$table->render();
function getStatusLabel(): array
{
return [
0 => "На модерации",
1 => "Активный",
2 => "Модератор",
99 => "Удален",
];
}