19 declare(strict_types=1);
72 protected ?ServerRequestInterface
$request = null;
82 protected ?
string $id = null;
89 protected ViewControl\
Factory $view_control_factory,
98 $this->checkArgListElements(
'columns', $columns, [Column::class]);
99 if ($columns === []) {
100 throw new \InvalidArgumentException(
'cannot construct a table without columns.');
104 $this->multi_action_signal = $signal_generator->
create();
105 $this->selection_signal = $signal_generator->
create();
106 $this->async_action_signal = $signal_generator->
create();
119 foreach ($columns as $id => $col) {
120 $ret[
$id] = $col->withIndex($idx++);
128 $sortable_visible_cols = array_filter(
130 static fn(
$c):
bool =>
$c->isSortable()
132 if ($sortable_visible_cols === []) {
133 return array_key_first($visible_cols);
135 return array_key_first($sortable_visible_cols);
148 return $this->data_retrieval;
156 $this->checkArgListElements(
'actions', $actions, [
T\
Action\Action::class]);
157 $clone = clone $this;
159 foreach ($actions as $id => $action) {
162 $clone->actions_single[
$id] = $action;
165 $clone->actions_multi[
$id] = $action;
168 $clone->actions_std[
$id] = $action;
175 public function withRequest(ServerRequestInterface $request): self
177 $clone = clone $this;
189 $clone = clone $this;
201 $clone = clone $this;
213 $clone = clone $this;
220 return $this->range ?? $this->data_factory->range(0, $this->number_of_rows);
225 $clone = clone $this;
237 $clone = clone $this;
277 return array_merge($this->actions_multi, $this->actions_std);
285 return array_merge($this->actions_single, $this->actions_std);
293 return array_merge($this->actions_single, $this->actions_multi, $this->actions_std);
298 return count($this->columns);
306 $clone = clone $this;
316 if (is_null($this->selected_optional_column_ids)) {
329 static fn(
$c):
bool =>
$c->isOptional()
340 static fn(
$c):
bool =>
$c->isInitiallyVisible()
352 fn(
Column $col,
string $col_id):
bool => !$col->
isOptional() || in_array($col_id, $visible_optional_columns,
true),
353 ARRAY_FILTER_USE_BOTH
359 return $this->data_row_builder
368 return $this->storage[$storage_id] ?? null;
376 $this->storage[$storage_id] =
$data;
382 ServerRequestInterface $request
385 $view_controls = $view_controls
386 ->withStoredInput($stored_values)
387 ->withRequest($request);
388 $this->
setStorageData($view_controls->getComponentInternalValues());
389 return $view_controls;
397 ?array $additional_parameters = []
400 $total_count = $this->
getDataRetrieval()->getTotalRowCount($filter_data, $additional_parameters);
404 # This retrieves container data from the request 406 $range =
$data[self::VIEWCONTROL_KEY_PAGINATION];
408 if ($range instanceof
Range) {
411 ->croppedTo($total_count ?? PHP_INT_MAX);
416 ->withOrder(
$data[self::VIEWCONTROL_KEY_ORDERING] ?? null)
417 ->withSelectedOptionalColumns(
$data[self::VIEWCONTROL_KEY_FIELDSELECTION] ?? null);
419 # This retrieves the view controls that should be displayed 420 $view_controls = $table->applyValuesToViewcontrols($table->getViewControls($total_count),
$request);
424 $table->withFilter($filter_data),
436 $view_controls = array_filter($view_controls);
437 return $this->view_control_container_factory->standard($view_controls);
442 $smallest_option = current(Pagination::DEFAULT_LIMITS);
443 if (is_null($total_count) || $total_count >= $smallest_option) {
446 $this->view_control_factory->pagination()
447 ->withTotalCount($total_count)
449 Pagination::FNAME_OFFSET => $range->
getStart(),
450 Pagination::FNAME_LIMIT => $range->
getLength()
453 return $this->view_control_factory->group([
454 $this->view_control_factory->nullControl(),
455 $this->view_control_factory->nullControl()
461 $sortable_visible_cols = array_filter(
463 static fn(
$c):
bool =>
$c->isSortable()
466 if ($sortable_visible_cols === []) {
471 foreach ($sortable_visible_cols as $col_id => $col) {
473 $order_asc = $this->data_factory->order($col_id,
Order::ASC);
474 $order_desc = $this->data_factory->order($col_id,
Order::DESC);
476 $labels = $col->getOrderingLabels();
477 $sort_options[$labels[0]] = $order_asc;
478 $sort_options[$labels[1]] = $order_desc;
480 return $this->view_control_factory->sortation($sort_options);
486 if ($optional_cols === []) {
490 return $this->view_control_factory
491 ->fieldSelection(array_map(
492 static fn(
$c):
string =>
$c->getTitle(),
500 $clone = clone $this;
507 if (null !== ($id = $this->
getId())) {
508 return self::STORAGE_ID_PREFIX .
$id;
getAdditionalParameters()
Signal $multi_action_signal
array $additional_parameters
withFilter(?array $filter)
getSelectedOptionalColumns()
This describes a Data Table.
getViewControlFieldSelection()
setStorageData(array $data)
getViewControlPagination(?int $total_count=null)
withRequest(ServerRequestInterface $request)
Rendering the Table must be done using the current Request: it (the request) will be forwarded to the...
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
applyValuesToViewcontrols(ViewControlContainer\ViewControl $view_controls, ServerRequestInterface $request)
ServerRequestInterface $request
__construct(SignalGeneratorInterface $signal_generator, protected ViewControl\Factory $view_control_factory, protected ViewControlContainer\Factory $view_control_container_factory, protected DataFactory $data_factory, protected DataRowBuilder $data_row_builder, string $title, array $columns, protected T\DataRetrieval $data_retrieval, protected \ArrayAccess $storage)
withId(string $id)
The DataTable comes with a storage to keep e.g.
array $selected_optional_column_ids
const VIEWCONTROL_KEY_FIELDSELECTION
const VIEWCONTROL_KEY_PAGINATION
Both the subject and the direction need to be specified when expressing an order. ...
getInitiallyVisibleColumns()
withAdditionalParameters(?array $additional_parameters)
Signal $async_action_signal
withNumberOfRows(int $number_of_rows)
Number of Rows is the amount of rows shown per page.
const VIEWCONTROL_KEY_ORDERING
getViewControls(?int $total_count=null)
applyViewControls(array $filter_data, ?array $additional_parameters=[])
create(string $class='')
Create a signal, each created signal MUST have a unique ID.
withMultiActionsPresent(bool $flag)
withSelectedOptionalColumns(?array $selected_optional_column_ids)
A simple class to express a range of whole positive numbers.
enumerateColumns(array $columns)
A Column describes the form of presentation for a certain aspect of data, i.e.
withActions(array $actions)