Skip to content
29 changes: 29 additions & 0 deletions demos/collection/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/* TODO - merge this into /demos/interactive/cardtable.php */
declare(strict_types=1);

namespace Atk4\Ui\Demos;

use Atk4\Ui\CardTable;
use Atk4\Ui\Table;

/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$m = new Country($app->db);
$m->addField('flag', [
'neverPersist' => true, // no need for actual value in this field
'ui' => [
'table' => [
Table\Column\CountryFlag::class,
[
'codeField' => $m->fieldName()->iso,
'nameField' => $m->fieldName()->name,
],
],
],
]);

$e = $m->loadAny();
$t = CardTable::addTo($app);
$t->setModel($e);
15 changes: 10 additions & 5 deletions src/CardTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ public function setModel(Model $model, array $columns = null): void
}

$data = [];
foreach ($model->get() as $key => $value) {
if (in_array($key, $columns, true)) {
foreach (array_keys($model->get()) as $fieldName) {
if (in_array($fieldName, $columns, true)) {
$data[] = [
'id' => $key,
'field' => $model->getField($key)->getCaption(),
'value' => $this->getApp()->uiPersistence->typecastSaveField($model->getField($key), $value),
'id' => $fieldName,
'field' => $model->getField($fieldName)->getCaption(),
'value' => new Model\EntityFieldPair($model, $fieldName),
];
}
}

$this->_bypass = true;

parent::setSource($data);
/*
$mm = parent::setSource($data);
$this->addDecorator('value', [Table\Column\Multiformat::class, function (Model $row) use ($model) {
$field = $model->getField($row->getId());
Expand All @@ -58,6 +61,8 @@ public function setModel(Model $model, array $columns = null): void

return [$ret];
}]);
*/

$this->_bypass = false;
}
}