68 parent::__construct(
$identifier, $model, $modelInstance);
71 $this->_emptyMessage =
new HtmlMessage(
"",
"nothing to display");
72 $this->_emptyMessage->setIcon(
"info circle");
76 if ($this->_runned !==
true) {
78 if ($this->_hasCheckboxes && isset($js)) {
81 if ($this->_visibleHover) {
82 $js->
execOn(
"mouseover",
"#" . $this->identifier .
" tr",
"$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [
83 "preventDefault" =>
false,
84 "stopPropagation" =>
true
86 $js->
execOn(
"mouseout",
"#" . $this->identifier .
" tr",
"$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [
87 "preventDefault" =>
false,
88 "stopPropagation" =>
true
91 if (\is_array($this->_deleteBehavior))
93 if (\is_array($this->_editBehavior))
95 if (\is_array($this->_displayBehavior)) {
99 if (isset($this->_pagination)) {
103 $this->_runned =
true;
108 if (isset($this->_urls[$op])) {
109 $params = \array_merge($params, [
110 "attr" =>
"data-ajax"
122 return $this->content[
"table"];
132 $this->
compile($jquery, $view);
135 ->getCell(0, $index);
139 if (! $this->_generated) {
140 if (isset($this->_buttonsColumn)) {
141 $this->_instanceViewer->sortColumnContent($this->_buttonsColumn, $this->_buttons);
143 $this->_instanceViewer->setInstance($this->_model);
144 $captions = $this->_instanceViewer->getCaptions();
145 $table = $this->content[
"table"];
146 if ($this->_hasCheckboxes) {
149 $table->setRowCount(0, \count($captions));
152 if (isset($this->_compileParts))
153 $table->setCompileParts($this->_compileParts);
160 $this->content = JArray::sortAssociative($this->content, [
165 if ($this->_caption !=
null) {
166 $this->
wrap(
"<div class='field'><label>{$this->_caption}</label>",
"</div>");
170 $this->_generated =
true;
172 return parent::compile($js, $view);
176 if ($this->_hasCheckboxes && $table->hasPart(
"thead")) {
179 ->addClass(
"no-sort");
182 if (isset($this->_toolbar)) {
185 if (isset($this->_pagination) && $this->_pagination->getVisible()) {
191 if (isset($this->_hiddenColumns))
193 if (isset($this->_colWidths)) {
194 foreach ($this->_colWidths as $colIndex => $width) {
195 $table->setColWidth($colIndex, $width);
201 foreach ($this->_hiddenColumns as $colIndex) {
202 $this->_self->hideColumn($colIndex);
208 $gbFields = $this->_instanceViewer->getGroupByFields();
209 if (\is_array($gbFields)) {
210 $captions = \array_values(JArray::removeByKeys($captions, $gbFields));
213 if (isset($this->_sortable)) {
220 if (isset($this->_pagination)) {
221 $objects = $this->_pagination->getObjects($this->_modelInstance);
223 InstanceViewer::setIndex(0);
224 $fields = $this->_instanceViewer->getSimpleProperties();
225 $groupByFields = $this->_instanceViewer->getGroupByFields();
226 if (! \is_array($groupByFields)) {
227 $table->fromDatabaseObjects($objects,
function ($instance) use ($table, $fields) {
231 $diffFields = \array_values(JArray::removeByKeys($fields, $groupByFields));
232 $activeValues = \array_combine($groupByFields, \array_fill(0, \count($groupByFields),
null));
234 $table->fromDatabaseObjects($objects,
function ($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids, $diffFields) {
235 $this->_instanceViewer->setInstance($instance);
236 foreach ($groupByFields as $index => $gbField) {
239 return $this->
_generateRow($instance, $diffFields, $table,
null, $uuids);
242 if ($table->getRowCount() == 0) {
243 $result = $table->addRow();
252 $newValue = $this->_instanceViewer->getValue($gbField);
257 $uuid = \uniqid(
"grp");
258 $uuids[$gbField] = $uuid;
259 $id = $this->_instanceViewer->getIdentifier();
260 $result = $table->addMergeRow(\count($fields) + 1, $newValue);
261 $result->setIdentifier($this->identifier .
"-tr-gb-" . $id);
262 $result->setProperty(
"data-ajax", $id);
263 $result->setProperty(
"data-group", $uuid);
264 $result->addToProperty(
"class", $this->_rowClass);
265 $activeValues[$gbField] = $newValue;
271 return $elm->getTextContent();
278 if (\is_numeric($index)) {
279 $values = $this->_instanceViewer->getValues();
280 if (isset($values[$index])) {
281 return $values[$index];
287 protected function _generateRow($instance, $fields, &$table, $checkedClass =
null, $uuids =
null) {
288 $this->_instanceViewer->setInstance($instance);
289 InstanceViewer::$index ++;
290 $values = $this->_instanceViewer->getValues();
291 $id = $this->_instanceViewer->getIdentifier();
294 if ($this->_hasCheckboxes) {
295 $ck =
new HtmlCheckbox(
"ck-" . $this->identifier .
"-" . $id,
"");
297 if (isset($this->_checkedCallback)) {
299 $checked = $func($instance);
301 $ck->setChecked($checked);
302 $field = $ck->getField();
303 $field->setProperty(
"value", $dataAjax);
304 $field->setProperty(
"name",
"selection[]");
305 if (isset($checkedClass))
306 $field->setClass($checkedClass);
307 \array_unshift($values, $ck);
309 $result = $table->newRow();
310 $result->setIdentifier($this->identifier .
"-tr-" . $id);
311 $result->setProperty(
"data-ajax", $dataAjax);
312 $result->setValues($values);
313 $result->addToProperty(
"class", $this->_rowClass);
314 $result->setPropertyValues(
"data-field", $fields);
316 $result->setProperty(
"data-child", implode(
" ", $uuids));
322 if (isset($this->_toolbar)) {
324 $this->_toolbar->setFloated(
"left");
326 $footer = $table->getFooter();
328 $this->_paginationToolbar = $this->_pagination->generateMenu($this->identifier);
329 $footer->addValues($this->_paginationToolbar);
333 if (isset($this->_urls[
"refresh"])) {
334 $menu = $this->_pagination->getMenu();
335 if (isset($menu) && isset($js)) {
336 $js->postOnClick(
"#" . $menu->getIdentifier() .
" .item", $this->_urls[
"refresh"],
"{'p':$(this).attr('data-page'),'_model':'" . JString::doubleBackSlashes($this->_model) .
"'}", $this->getRefreshSelector(), [
337 "preventDefault" =>
false,
338 "jqueryDone" =>
"replaceWith",
339 "hasLoader" =>
false,
340 "jsCallback" =>
'$("#' . $this->identifier .
'").trigger("pageChange");$("#' . $this->identifier .
'").trigger("activeRowChange");'
342 $page = $_POST[
"p"] ??
null;
345 $js->execAtLast(
'$("#' . $this->
getIdentifier() .
' .pagination").children("a.item").removeClass("' . $activeClass .
'");$("#' . $this->
getIdentifier() .
' .pagination").children("a.item[data-page=' . $page .
']:not(.no-active)").addClass("' . $activeClass .
'");');
352 if (isset($this->_searchField) && isset($js) && isset($this->_urls[
"refresh"])) {
353 $this->_searchField->postOn(
"change", $this->_urls[
"refresh"],
"{'s':$(self).val(),'_model':'" . JString::doubleBackSlashes($this->_model) .
"'}",
"#" . $this->identifier .
" tbody", [
354 "preventDefault" =>
false,
355 "jqueryDone" =>
"replaceWith",
356 "hasLoader" =>
"internal",
357 "jsCallback" =>
'$("#' . $this->identifier .
'").trigger("searchTerminate",[$(self).val()]);'
365 $fieldName = parent::_getFieldName($index);
366 if (\is_object($fieldName))
367 $fieldName =
"field-" . $index;
368 if ($this->_namePrefix !=
null) {
369 $fieldName = $this->_namePrefix .
'.' . $fieldName;
371 return $fieldName .
"[]";
382 if (isset($this->_compileParts) ===
false) {
395 if (\is_array($this->_toolbarPosition)) {
396 foreach ($this->_toolbarPosition as $tbp) {
415 $this->_instanceViewer->afterCompile($index, $callback);
420 $hasPart = $table->hasPart($part);
422 $row = $table->getPart($part)->addRow(\count($captions));
424 $row = $table->getPart($part)->getRow(0);
439 return $this->content[
"table"];
455 if (\is_array($urls)) {
456 $this->_urls[
"refresh"] = JArray::getValue($urls,
"refresh", 0);
457 $this->_urls[
"edit"] = JArray::getValue($urls,
"edit", 1);
458 $this->_urls[
"delete"] = JArray::getValue($urls,
"delete", 2);
459 $this->_urls[
"display"] = JArray::getValue($urls,
"display", 3);
484 public function paginate($page, $total_rowcount, $items_per_page = 10, $pages_visibles =
null) {
485 $this->_pagination =
new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount);
500 public function autoPaginate($page = 1, $items_per_page = 10, $pages_visibles = 4) {
501 $this->_pagination =
new Pagination($items_per_page, $pages_visibles, $page);
513 $this->_compileParts = $compileParts;
525 ->setPosition($position);
529 if (isset($this->_searchField) ===
false) {
530 $this->_searchField =
new HtmlInput(
"search-" . $this->identifier,
"search",
"",
"Search...");
531 $this->_searchField->addIcon(
"search", Direction::RIGHT);
544 $this->content[
"table"]->onNewRow($callback);
559 if (! isset($result[$op]))
583 if (isset($this->_refreshSelector))
585 return "#" . $this->identifier .
" tbody";
603 public function show($modelInstance) {
604 if (\is_array($modelInstance)) {
605 if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0]))
606 $modelInstance = \json_decode(\json_encode($modelInstance), FALSE);
608 $this->_modelInstance = $modelInstance;
638 $this->_sortable = $colIndex;
643 $this->_self->setActiveRowSelector($class, $event, $multiple);
648 return $this->_self->getActiveRowClass();
652 return $this->_self->hasActiveRowSelector();
656 if (! \is_array($this->_hiddenColumns))
657 $this->_hiddenColumns = [];
658 $this->_hiddenColumns[] = $colIndex;
663 $this->_colWidths[$colIndex] = $width;
673 $this->content[
"table"]->setColAlignment($colIndex, $alignment);
677 public function trigger($event, $params =
"[]") {
723 return $this->_instanceViewer->getGroupByFields();
731 $this->_instanceViewer->setGroupByFields($_groupByFields);
736 if ($index !==
false) {
737 $this->_instanceViewer->addGroupBy($index);
760 $this->_emptyMessage->setInverted($recursive);
765 $this->content[
"table"]->setFocusable($focusable);
769 $this->_caption = $caption;
785 $this->_namePrefix = $namePrefix;
execOn($event, $element, $js, $parameters=array())
Executes the javascript code $js when $event fires on $element.
ajaxOnClick($element, $url, $responseElement='', $parameters=array())
Performs a get to $url on the click event on $element and display it in $responseElement.
Base class for Semantic double elements.
Semantic Message component.
Semantic HTML Table component.
setHeaderValues($values=array())
Sets the header values.
setSortable($colIndex=NULL)