expected output: > ILIAS shows the rendered Component.
This is what the table will look like: Columns define the nature (and thus: shape) of one field/aspect of the data record. Also, some functions of the table are set per column, e.g. sortability
Define actions: An Action is an URL carrying a parameter that references the targeted record(s). Standard Actions apply to both a collection of records as well as a single entry, while Single- and Multiactions will only work for one of them. Also see the docu-entries for Actions.
this is the endpoint for actions, in this case the same page.
Actions' commands and the row-ids affected are relayed to the server via GET. The URLBuilder orchestrates query-paramters (a.o. by assigning namespace)
We have to claim those parameters. In return, there is a token to modify the value of the param; the tokens will work only with the given copy of URLBuilder, so acquireParameters will return the builder as first entry, followed by the tokens.
array<string, Action> [action_id => Action]
the label as shown in dropdowns
set the actions-parameter's value; will become '&datatable_example_table_action=edit'
the Table will need to modify the values of this parameter; give the token.
An async Action will trigger an AJAX-call to the action's target and display the results in a modal-layer over the Table. Parameters are passed to the call, but you will have to completely build the contents of the response. DO NOT render an entire page ;)
Configure the Table to retrieve data with an instance of DataRetrieval; the table itself is agnostic of the source or the way of retrieving records. However, it provides View Controls and therefore parameters that will influence the way data is being retrieved. E.g., it is usually a good idea to delegate sorting to the database, or limit records to the amount of actually shown rows. Those parameters are being provided to DataRetrieval::getRows.
Actions may be disabled for specific rows:
setup the Table and hand over the request; with an ID for the table, parameters will be stored throughout url changes
build some output.
get the desired action from query; the parameter is namespaced, but we still have the token and it knows its name:
also get the row-ids and build some listing
take care of the async-call; 'delete'-action asks for it.
otherwise, we want the table and the results below
Definition at line 36 of file base.php.
References Vendor\Package\$a, Vendor\Package\$b, $DIC, Vendor\Package\$f, $id, $out, $r, ILIAS\UI\Implementation\Component\Table\$range, ILIAS\UI\examples\Layout\Page\Standard\$refinery, ILIAS\__construct(), ILIAS\Data\Order\DESC, exit, ILIAS\Data\Range\getLength(), ILIAS\Data\Range\getStart(), ILIAS\Data\Order\join(), and null.
39 $f = $DIC[
'ui.factory'];
40 $r = $DIC[
'ui.renderer'];
41 $df = new \ILIAS\Data\Factory();
43 $request = $DIC->http()->request();
51 'usr_id' =>
$f->table()->column()->number(
"User ID")
52 ->withIsSortable(
false),
53 'login' =>
$f->table()->column()->text(
"Login")
54 ->withHighlight(
true),
55 'email' =>
$f->table()->column()->eMail(
"eMail"),
56 'last' =>
$f->table()->column()->date(
"last login", $df->dateFormat()->germanLong()),
57 'achieve' =>
$f->table()->column()->statusIcon(
"progress")
58 ->withIsOptional(
true),
59 'achieve_txt' =>
$f->table()->column()->status(
"success")
60 ->withIsSortable(
true)
61 ->withIsOptional(
true,
false),
62 'repeat' =>
$f->table()->column()->boolean(
"repeat",
'yes',
'no')
63 ->withIsSortable(
false),
64 'fee' =>
$f->table()->column()->number(
"Fee")
66 ->withUnit(
'£',
I\Column\Number::UNIT_POSITION_FORE)
67 ->withOrderingLabels(
'cheapest first',
'most expensive first'),
68 'failure_txt' =>
$f->table()->column()->status(
"failure")
69 ->withIsSortable(
false)
70 ->withIsOptional(
true,
false),
82 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
88 $url_builder =
new URLBuilder($here_uri);
89 $query_params_namespace = [
'datatable',
'example'];
97 list($url_builder, $action_parameter_token, $row_id_token) =
98 $url_builder->acquireParameters(
99 $query_params_namespace,
108 'edit' =>
$f->table()->action()->single(
112 $url_builder->withParameter($action_parameter_token,
"edit"),
116 'compare' =>
$f->table()->action()->multi(
118 $url_builder->withParameter($action_parameter_token,
"compare"),
122 $f->table()->action()->standard(
124 $url_builder->withParameter($action_parameter_token,
"delete"),
135 $f->table()->action()->standard(
137 $url_builder->withParameter($action_parameter_token,
"info"),
154 $data_retrieval =
new class (
$f,
$r) implements
I\DataRetrieval {
156 protected \
ILIAS\
UI\Factory $ui_factory,
161 public function getRows(
162 I\DataRowBuilder $row_builder,
163 array $visible_column_ids,
167 ?array $additional_parameters
169 $records = $this->getRecords($range, $order);
170 foreach ($records as $idx => $record) {
171 $row_id = (string) $record[
'usr_id'];
172 $record[
'achieve_txt'] = $record[
'achieve'] > 80 ?
'passed' :
'failed';
173 $record[
'failure_txt'] =
"not " . $record[
"achieve_txt"];
174 $record[
'repeat'] = $record[
'achieve'] < 80;
177 $this->ui_factory->symbol()->icon()->custom(
'assets/images/standard/icon_checked.svg',
'',
'small'),
178 $this->ui_factory->symbol()->icon()->custom(
'assets/images/standard/icon_unchecked.svg',
'',
'small'),
179 $this->ui_factory->symbol()->icon()->custom(
'assets/images/standard/icon_x.svg',
'',
'small'),
182 if ($record[
'achieve'] > 80) {
185 if ($record[
'achieve'] < 30) {
188 $record[
'achieve'] = $icon;
190 yield $row_builder->buildDataRow($row_id, $record)
192 ->withDisabledAction(
'delete', ($record[
'login'] ===
'superuser'));
196 public function getTotalRowCount(
198 ?array $additional_parameters
200 return count($this->getRecords());
203 protected function getRecords(?Range $range =
null, ?Order $order =
null): array
206 [
'usr_id' => 123,
'login' =>
'superuser',
'email' =>
'user@example.com',
207 'last' => (new \DateTimeImmutable())->modify(
'-1 day') ,
'achieve' => 20,
'fee' => 0
209 [
'usr_id' => 867,
'login' =>
'student1',
'email' =>
'student1@example.com',
210 'last' => (new \DateTimeImmutable())->modify(
'-10 day'),
'achieve' => 90,
'fee' => 40
212 [
'usr_id' => 8923,
'login' =>
'student2',
'email' =>
'student2@example.com',
213 'last' => (new \DateTimeImmutable())->modify(
'-8 day'),
'achieve' => 66,
'fee' => 36.789
215 [
'usr_id' => 8748,
'login' =>
'student3_longname',
'email' =>
'student3_long_email@example.com',
216 'last' => (new \DateTimeImmutable())->modify(
'-300 day'),
'achieve' => 8,
'fee' => 36.789
218 [
'usr_id' => 8749,
'login' =>
'studentAB',
'email' =>
'studentAB@example.com',
219 'last' => (new \DateTimeImmutable())->modify(
'-7 day'),
'achieve' => 100,
'fee' => 114
221 [
'usr_id' => 8750,
'login' =>
'student5',
'email' =>
'student5@example.com',
222 'last' => new \DateTimeImmutable(),
'achieve' => 76,
'fee' => 3.789
224 [
'usr_id' => 8751,
'login' =>
'student6',
'email' =>
'student6@example.com',
225 'last' => (new \DateTimeImmutable())->modify(
'-2 day'),
'achieve' => 66,
'fee' => 67
229 list($order_field, $order_direction) = $order->join([], fn($ret, $key, $value) => [$key, $value]);
230 usort($records, fn(
$a,
$b) =>
$a[$order_field] <=>
$b[$order_field]);
231 if ($order_direction ===
'DESC') {
232 $records = array_reverse($records);
236 $records = array_slice($records, $range->getStart(), $range->getLength());
249 ->data($data_retrieval,
'a data table', $columns)
250 ->withId(
'example_base')
251 ->withActions($actions)
255 ->withRange(
new Range(0, 2))
256 ->withOrder(
new Order(
'achieve', Order::DESC))
258 ->withRequest($request);
269 $query = $DIC->http()->wrapper()->query();
270 if ($query->has($action_parameter_token->getName())) {
271 $action = $query->retrieve($action_parameter_token->getName(),
$refinery->to()->string());
273 $ids = $query->retrieve($row_id_token->getName(),
$refinery->custom()->transformation(fn($v) => $v));
274 $listing =
$f->listing()->characteristicValue()->text([
275 'table_action' => $action,
276 'id' => print_r($ids,
true),
280 if ($action ===
'delete') {
282 foreach ($ids as
$id) {
283 $items[] =
$f->modal()->interruptiveItem()->keyValue($id, $row_id_token->getName(),
$id);
285 echo(
$r->renderAsync([
286 $f->modal()->interruptive(
288 'You are about to delete items!',
290 )->withAffectedItems($items)
291 ->withAdditionalOnLoadCode(
static fn($id):
string =>
"console.log('ASYNC JS');")
295 if ($action ===
'info') {
297 $r->render(
$f->messageBox()->info(
'an info message: <br><li>' . implode(
'<li>', $ids)))
298 .
'<script data-replace-marker="script">console.log("ASYNC JS, too");</script>' 304 $out[] =
$f->divider()->horizontal();
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
__construct(Container $dic, ilPlugin $plugin)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...