69 parent::__construct(
$identifier, $model, $modelInstance);
72 $this->_emptyMessage =
new HtmlMessage(
"",
"nothing to display");
73 $this->_emptyMessage->setIcon(
"info circle");
77 if ($this->_runned !==
true) {
79 if ($this->_hasCheckboxes && isset($js)) {
82 if ($this->_visibleHover) {
83 $js->execOn(
"mouseover",
"#" . $this->identifier .
" tr",
"$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [
84 "preventDefault" =>
false,
85 "stopPropagation" =>
true 87 $js->execOn(
"mouseout",
"#" . $this->identifier .
" tr",
"$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [
88 "preventDefault" =>
false,
89 "stopPropagation" =>
true 92 if (\is_array($this->_deleteBehavior))
94 if (\is_array($this->_editBehavior))
96 if (\is_array($this->_displayBehavior)) {
100 if (isset($this->_pagination)) {
104 $this->_runned =
true;
109 if (isset($this->_urls[$op])) {
110 $params = \array_merge($params, [
111 "attr" =>
"data-ajax" 113 $js->ajaxOnClick(
"#" . $this->identifier .
" ._" . $op, $this->_urls[$op], $this->
getTargetSelector($op), $params);
123 return $this->content[
"table"];
133 $this->
compile($jquery, $view);
136 ->getCell(0, $index);
140 if (! $this->_generated) {
141 if (isset($this->_buttonsColumn)) {
142 $this->_instanceViewer->sortColumnContent($this->_buttonsColumn, $this->_buttons);
144 $this->_instanceViewer->setInstance($this->_model);
145 $captions = $this->_instanceViewer->getCaptions();
146 $table = $this->content[
"table"];
147 if ($this->_hasCheckboxes) {
150 $table->setRowCount(0, \
count($captions));
153 if (isset($this->_compileParts))
154 $table->setCompileParts($this->_compileParts);
166 if ($this->_caption != null) {
167 $this->
wrap(
"<div class='field'><label>{$this->_caption}</label>",
"</div>");
171 $this->_generated =
true;
173 return parent::compile($js, $view);
177 if ($this->_hasCheckboxes && $table->hasPart(
"thead")) {
180 ->addClass(
"no-sort");
183 if (isset($this->_toolbar)) {
186 if (isset($this->_pagination) && $this->_pagination->getVisible()) {
192 if (isset($this->_hiddenColumns))
194 if (isset($this->_colWidths)) {
195 foreach ($this->_colWidths as $colIndex => $width) {
196 $table->setColWidth($colIndex, $width);
202 foreach ($this->_hiddenColumns as $colIndex) {
203 $this->_self->hideColumn($colIndex);
209 $gbFields = $this->_instanceViewer->getGroupByFields();
210 if (\is_array($gbFields)) {
214 if (isset($this->_sortable)) {
215 $table->setSortable($this->_sortable);
221 if (isset($this->_pagination)) {
222 $objects = $this->_pagination->getObjects($this->_modelInstance);
225 $fields = $this->_instanceViewer->getSimpleProperties();
226 $groupByFields = $this->_instanceViewer->getGroupByFields();
227 if (! \is_array($groupByFields)) {
228 $table->fromDatabaseObjects($objects,
function ($instance) use ($table, $fields) {
233 $activeValues = \array_combine($groupByFields, \array_fill(0, \
count($groupByFields), null));
235 $table->fromDatabaseObjects($objects,
function ($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids, $diffFields) {
236 $this->_instanceViewer->setInstance($instance);
237 foreach ($groupByFields as $index => $gbField) {
240 return $this->
_generateRow($instance, $diffFields, $table, null, $uuids);
243 if ($table->getRowCount() == 0) {
244 $result = $table->addRow();
253 $newValue = $this->_instanceViewer->getValue($gbField);
258 $uuid = \uniqid(
"grp");
259 $uuids[$gbField] = $uuid;
260 $id = $this->_instanceViewer->getIdentifier();
261 $result = $table->addMergeRow(\
count($fields) + 1, $newValue);
262 $result->setIdentifier($this->identifier .
"-tr-gb-" . $id);
263 $result->setProperty(
"data-ajax", $id);
264 $result->setProperty(
"data-group", $uuid);
265 $result->addToProperty(
"class", $this->_rowClass);
266 $activeValues[$gbField] = $newValue;
272 return $elm->getTextContent();
279 if (\is_numeric($index)) {
280 $values = $this->_instanceViewer->getValues();
281 if (isset($values[$index])) {
282 return $values[$index];
288 protected function _generateRow($instance, $fields, &$table, $checkedClass = null, $uuids = null) {
289 $this->_instanceViewer->setInstance($instance);
291 $values = $this->_instanceViewer->getValues();
292 $id = $this->_instanceViewer->getIdentifier();
295 if ($this->_hasCheckboxes) {
296 $ck =
new HtmlCheckbox(
"ck-" . $this->identifier .
"-" . $id,
"");
298 if (isset($this->_checkedCallback)) {
300 $checked = $func($instance);
302 $ck->setChecked($checked);
303 $field = $ck->getField();
304 $field->setProperty(
"value", $dataAjax);
305 $field->setProperty(
"name",
"selection[]");
306 if (isset($checkedClass))
307 $field->setClass($checkedClass);
308 \array_unshift($values, $ck);
310 $result = $table->newRow();
311 $result->setIdentifier($this->identifier .
"-tr-" . $id);
312 $result->setProperty(
"data-ajax", $dataAjax);
313 $result->setValues($values);
314 $result->addToProperty(
"class", $this->_rowClass);
315 $result->setPropertyValues(
"data-field", $fields);
317 $result->setProperty(
"data-child", implode(
" ", $uuids));
323 if (isset($this->_toolbar)) {
325 $this->_toolbar->setFloated(
"left");
327 $footer = $table->getFooter();
329 $this->_paginationToolbar = $this->_pagination->generateMenu($this->identifier);
330 $footer->addValues($this->_paginationToolbar);
334 if (isset($this->_urls[
"refresh"])) {
335 $menu = $this->_pagination->getMenu();
336 if (isset($menu) && isset($js)) {
338 "preventDefault" =>
false,
339 "jqueryDone" =>
"replaceWith",
340 "hasLoader" =>
false,
341 "jsCallback" =>
'$("#' . $this->identifier .
'").trigger("pageChange");$("#' . $this->identifier .
'").trigger("activeRowChange");' 343 $page = $_POST[
"p"] ?? null;
346 $js->execAtLast(
'$("#' . $this->
getIdentifier() .
' .pagination").children("a.item").removeClass("' . $activeClass .
'");$("#' . $this->
getIdentifier() .
' .pagination").children("a.item[data-page=' . $page .
']:not(.no-active)").addClass("' . $activeClass .
'");');
353 if (isset($this->_searchField) && isset($js) && isset($this->_urls[
"refresh"])) {
354 $this->_searchField->postOn(
"change", $this->_urls[
"refresh"],
"{'s':$(self).val(),'_model':'" .
JString::doubleBackSlashes($this->_model) .
"'}",
"#" . $this->identifier .
" tbody", [
355 "preventDefault" =>
false,
356 "jqueryDone" =>
"replaceWith",
357 "hasLoader" =>
"internal",
358 "jsCallback" =>
'$("#' . $this->identifier .
'").trigger("searchTerminate",[$(self).val()]);' 367 if (\is_object($fieldName))
368 $fieldName =
"field-" . $index;
369 if ($this->_namePrefix != null) {
370 $fieldName = $this->_namePrefix .
'.' . $fieldName;
372 return $fieldName .
"[]";
383 if (isset($this->_compileParts) ===
false) {
396 if (\is_array($this->_toolbarPosition)) {
397 foreach ($this->_toolbarPosition as $tbp) {
416 $this->_instanceViewer->afterCompile($index, $callback);
421 $hasPart = $table->hasPart($part);
423 $row = $table->getPart($part)->addRow(\
count($captions));
425 $row = $table->getPart($part)->getRow(0);
440 return $this->content[
"table"];
456 if (\is_array($urls)) {
485 public function paginate($page, $total_rowcount, $items_per_page = 10, $pages_visibles = null) {
486 $this->_pagination =
new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount);
501 public function autoPaginate($page = 1, $items_per_page = 10, $pages_visibles = 4) {
502 $this->_pagination =
new Pagination($items_per_page, $pages_visibles, $page);
514 $this->_compileParts = $compileParts;
526 ->setPosition($position);
530 if (isset($this->_searchField) ===
false) {
531 $this->_searchField =
new HtmlInput(
"search-" . $this->identifier,
"search",
"",
"Search...");
545 $this->content[
"table"]->onNewRow($callback);
560 if (! isset($result[$op]))
584 if (isset($this->_refreshSelector))
586 return "#" . $this->identifier .
" tbody";
604 public function show($modelInstance) {
605 if (\is_array($modelInstance)) {
606 if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0]))
607 $modelInstance = \json_decode(\json_encode($modelInstance), FALSE);
609 $this->_modelInstance = $modelInstance;
639 $this->_sortable = $colIndex;
644 $this->_self->setActiveRowSelector($class, $event, $multiple);
649 return $this->_self->getActiveRowClass();
653 return $this->_self->hasActiveRowSelector();
657 if (! \is_array($this->_hiddenColumns))
658 $this->_hiddenColumns = [];
659 $this->_hiddenColumns[] = $colIndex;
664 $this->_colWidths[$colIndex] = $width;
674 $this->content[
"table"]->setColAlignment($colIndex, $alignment);
678 public function trigger($event, $params =
"[]") {
724 return $this->_instanceViewer->getGroupByFields();
732 $this->_instanceViewer->setGroupByFields($_groupByFields);
737 if ($index !==
false) {
738 $this->_instanceViewer->addGroupBy($index);
761 $this->_emptyMessage->setInverted($recursive);
766 $this->content[
"table"]->setFocusable($focusable);
770 $this->_caption = $caption;
786 $this->_namePrefix = $namePrefix;
static getValue($array, $key, $pos)
Semantic Message component.
static doubleBackSlashes($value)
setHeaderValues($values=array())
Sets the header values.
Semantic HTML Table component.
Base class for Semantic double elements.
static removeByKeys($array, $keys)
static sortAssociative($array, $sortedKeys=array())