Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 48 additions & 59 deletions demos/collection/table.php
Original file line number Diff line number Diff line change
@@ -1,84 +1,73 @@
<?php

declare(strict_types=1);
date_default_timezone_set('UTC');
include 'init.php';

namespace Atk4\Ui\Demos;
// 1st table
$bb = $app->add(['View', 'ui' => 'buttons']);
$table = $app->add(['Table', 'celled' => true]);

use Atk4\Data\Model;
use Atk4\Ui\Button;
use Atk4\Ui\Js\JsReload;
use Atk4\Ui\Js\JsToast;
use Atk4\Ui\Table;
use Atk4\Ui\View;
$bb->add(['Button', 'Refresh Table', 'icon' => 'refresh'])
->on('click', new \atk4\ui\jsReload($table));

/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
$bb->on('click', $table->js()->reload());

if ($_GET['id'] ?? null) {
$app->layout->js(true, new JsToast('Details link is in simulation mode.'));
}
$table->setModel(new SomeData(), false);

$bb = View::addTo($app, ['ui' => 'buttons']);

$table = Table::addTo($app, ['class.celled' => true]);
Button::addTo($bb, ['Refresh Table', 'icon' => 'refresh'])
->on('click', new JsReload($table));

$table->setModel(new SomeData(), []);

$table->addColumn('name', new Table\Column\Link(['table', 'foo' => 'bar'], ['person_id' => 'id'], ['target' => '_blank']));
$table->addColumn('surname', new Table\Column\Template('{$surname}'))->addClass('warning');
$table->addColumn('title', new Table\Column\Status([
$table->addColumn('name', new \atk4\ui\TableColumn\Link(['details'], ['id' => 'id']));
$table->addColumn('surname', new \atk4\ui\TableColumn\Template('{$surname}'))->addClass('warning');
$table->addColumn('title', new \atk4\ui\TableColumn\Status([
'positive' => ['Prof.'],
'negative' => ['Dr.'],
]));

$table->addColumn('date');
$table->addColumn('salary', new Table\Column\Money());
$table->addColumn('logo_url', [Table\Column\Image::class, 'caption' => 'Our Logo']);

$table->onHook(Table\Column::HOOK_GET_HTML_TAGS, function (Table $table, Model $row) {
switch ($row->getId()) {
case 1:
$color = 'yellow';

break;
case 2:
$color = 'grey';
$table->addColumn('salary', new \atk4\ui\TableColumn\Money()); //->addClass('right aligned single line', 'all'));

break;
case 3:
$color = 'brown';

break;
default:
$color = '';
}
if ($color) {
$table->addHook('getHTMLTags', function ($table, $row) {
if ($row->id == 1) {
return [
'name' => $table->getApp()->getTag('div', ['class' => 'ui ribbon ' . $color . ' label'], $row->get('name')),
'name' => $table->app->getTag('div', ['class' => 'ui ribbon label'], $row['name']),
];
}
});

$table->addTotals([
'name' => 'Totals:',
'salary' => ['sum'],
'name' => 'Total {$_row_count} rows:',
'surname'=> [
// longest surname
'compare'=> function ($total, $value, $model) {
return strlen($value) > strlen($total) ? $value : $total;
},
'title'=> function ($total, $model) {
return 'Shortes is: '.$total;
},
],
'salary' => [
'init' => '123',
'update'=> null,
],
]);

$myArray = [
['name' => 'Vinny', 'surname' => 'Sihra', 'birthdate' => '1973-02-03', 'cv' => 'I am <strong>BIG</strong> Vinny'],
['name' => 'Zoe', 'surname' => 'Shatwell', 'birthdate' => '1958-08-21', 'cv' => null],
['name' => 'Darcy', 'surname' => 'Wild', 'birthdate' => '1968-11-01', 'cv' => 'I like <i style="color: orange;>icecream</i>'],
['name' => 'Brett', 'surname' => 'Bird', 'birthdate' => '1988-12-20', 'cv' => null],
// 2nd table
$my_array = [
['name' => 'Vinny', 'surname' => 'Sihra', 'birthdate' => new \DateTime('1973-02-03')],
['name' => 'Zoe', 'surname' => 'Shatwell', 'birthdate' => new \DateTime('1958-08-21')],
['name' => 'Darcy', 'surname' => 'Wild', 'birthdate' => new \DateTime('1968-11-01')],
['name' => 'Brett', 'surname' => 'Bird', 'birthdate' => new \DateTime('1988-12-20')],
];

$table = Table::addTo($app);
$table->setSource($myArray, ['name']);
$table = $app->add('Table');

$table->setSource($my_array, ['name']);

$table->addColumn('no');

$table->addHook('beforeRow', function ($t) {
$t->model['no'] = @++$t->npk;
});

// $table->addColumn('name');
$table->addColumn('surname', [Table\Column\Link::class, 'url' => 'table.php?id={$surname}']);
$table->addColumn('birthdate', [], ['type' => 'date']);
$table->addColumn('cv', [Table\Column\Html::class]);
//$table->addColumn('name');
$table->addColumn('surname', ['Link', 'url' => 'details.php?surname={$surname}']);
$table->addColumn('birthdate', null, ['type' => 'date']);

$table->getColumnDecorators('name')[0]->addClass('disabled');
Loading