46 parent::__construct(
$identifier,
"table",
"ui table");
47 $this->content = array();
49 $this->_variations = [
54 $this->_compileParts = [
59 $this->_afterCompileEvents = [];
69 if (\array_key_exists($key, $this->content) ===
false) {
71 if ($key !==
"tbody") {
72 $this->content[$key]->setRowCount(1, $this->_colCount);
75 return $this->content[$key];
79 if (isset($this->content[
"thead"])) {
80 return $this->content[
"thead"];
82 return $this->content[
"tbody"];
100 return $this->
getPart(
"tbody")->count();
109 return $this->
getPart(
"thead");
118 return $this->
getPart(
"tfoot");
128 return \array_key_exists($key, $this->content) ===
true;
138 $this->_colCount = $colCount;
139 return $this->
getBody()->setRowCount($rowCount, $colCount);
150 return $this->
getBody()->getCell($row, $col);
160 return $this->
getBody()->getRow($rowIndex);
169 public function addRow($values = array()) {
170 $row = $this->
getBody()->addRow($this->_colCount);
171 $row->setValues(\array_values($values));
181 return $this->
getBody()->newRow($this->_colCount);
192 $this->
getBody()->setValues($values);
203 return $this->
getHeader()->setValues($values);
213 return $this->
getFooter()->setValues($values);
224 $this->
getBody()->setColValues($colIndex, $values);
236 $this->
getBody()->setRowValues($rowIndex, $values);
241 return $this->
getBody()->addColVariations($colIndex, $variations);
251 return $this->
colAlign($colIndex,
"colCenter");
261 return $this->
colAlign($colIndex,
"colRight");
271 return $this->
colAlign($colIndex,
"colLeft");
281 return $this->
colAlign($colIndex,
"colCenterFromRight");
291 return $this->
colAlign($colIndex,
"colRightFromRight");
301 return $this->
colAlign($colIndex,
"colLeftFromRight");
305 switch ($alignment) {
306 case TextAlignment::LEFT:
307 $function =
"colLeft";
310 case TextAlignment::RIGHT:
311 $function =
"colRight";
314 case TextAlignment::CENTER:
315 $function =
"colCenter";
319 $function =
"colLeft";
321 $this->
colAlign($colIndex, $function);
326 switch ($alignment) {
327 case TextAlignment::LEFT:
328 $function =
"colLeftFromRight";
331 case TextAlignment::RIGHT:
332 $function =
"colRightFromRight";
335 case TextAlignment::CENTER:
336 $function =
"colCenterFromRight";
340 $function =
"colLeftFromRight";
342 $this->
colAlign($colIndex, $function);
347 if (\is_array($colIndex)) {
348 foreach ($colIndex as $cIndex) {
349 $this->
colAlign($cIndex, $function);
353 $this->
getHeader()->$function($colIndex);
355 $this->
getBody()->$function($colIndex);
370 $this->
getBody()->conditionalCellFormat($callback, $format);
384 $this->
getBody()->conditionalRowFormat($callback, $format);
395 $this->
getBody()->applyCells($callback);
406 $this->
getBody()->applyRows($callback);
417 if (\
sizeof($this->_compileParts) < 3) {
418 $this->_template =
"%content%";
421 $this->content = JArray::sortAssociative($this->content, $this->_compileParts);
422 return parent::compile($js, $view);
426 parent::compile_once($js, $view);
428 $this->
addEvent(
"execute",
"$('#" . $this->identifier .
"').tablesort().data('tablesort').sort($('th.default-sort'));");
439 $result = $function($object);
440 if (\is_array($result)) {
441 $result = $this->
addRow($function($object));
443 $result = $this->
getBody()->_addRow($result);
445 if (isset($this->_afterCompileEvents[
"onNewRow"])) {
446 if (\is_callable($this->_afterCompileEvents[
"onNewRow"]))
447 $this->_afterCompileEvents[
"onNewRow"]($result, $object);
462 $this->_compileParts = $parts;
468 $this->
getPart(
"tbody")->refreshTR();
474 $js->exec(
'$("#' . $this->identifier .
' tfoot").replaceWith("' . \addslashes($this->_footer) .
'");',
true);
479 if (! $this->_runned) {
480 if (isset($this->_activeRowSelector)) {
481 $this->_activeRowSelector->run();
484 $result = parent::run($js);
485 if (isset($this->_footer))
486 $this->_footer->run($js);
487 $this->_runned =
true;
499 $this->_afterCompileEvents[
"onNewRow"] = $callback;
512 $this->_activeRowSelector =
new ActiveRow($this, $class, $event, $multiple);
517 if (isset($this->_activeRowSelector)) {
518 return $this->_activeRowSelector->getClass();
524 return isset($this->_activeRowSelector);
528 if (isset($this->content[
"thead"])) {
529 $this->content[
"thead"]->hideColumn($colIndex);
531 $this->content[
"tbody"]->hideColumn($colIndex);
532 if (isset($this->content[
"tfoot"])) {
533 $this->content[
"tfoot"]->hideColumn($colIndex);
540 if ($part !==
null && $part->count() > 0)
541 $part->getCell(0, $colIndex)->setWidth($width);
547 if ($part !==
null && $part->count() > 0) {
548 $count = $part->getColCount();
549 if (! \is_array($widths)) {
550 $widths = \array_fill(0, $count, $widths);
552 $max = \min(\
sizeof($widths), $count);
553 for ($i = 0; $i < $max; $i ++) {
554 $part->getCell(0, $i)->setWidth($widths[$i]);
562 $body->mergeIdentiqualValues($colIndex, $function);
583 $this->
on(
"activeRowChange", $jsCode);
588 return $this->
getBody()->addMergeRow($colCount, $value);
BaseHtml for HTML components.
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
propertyContains($propertyName, $value)
Base class for Semantic double elements.
A class for row selection in Table or DataTable.
Semantic HTML Table component.
setFooterValues($values=array())
Sets the footer values.
colLeftFromRight($colIndex)
Sets col alignment to left.
setHeaderValues($values=array())
Sets the header values.
setRowCount($rowCount, $colCount)
applyCells($callback)
Applies a callback function on each cell.
mergeIdentiqualValues($colIndex, $function="strip_tags")
run(JsUtils $js)
{{SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()}HtmlDoubleElement:...
conditionalRowFormat($callback, $format)
Applies a format on each row when $callback returns true.
addRow($values=array())
Adds a new row and sets $values to his cols.
colLeft($colIndex)
Sets col alignment to left.
setColAlignment($colIndex, $alignment)
setActiveRowSelector($class="active", $event="click", $multiple=false)
Defines how a row is selectable.
addColVariations($colIndex, $variations=array())
conditionalCellFormat($callback, $format)
Applies a format on each cell when $callback returns true.
applyRows($callback)
Applies a callback function on each row.
newRow()
adds and returns a new row
setInnerScript($_innerScript)
hasPart($key)
Checks if the part corresponding to $key exists.
__construct($identifier, $rowCount, $colCount)
colCenterFromRight($colIndex)
Sets the col alignment to center.
setColValues($colIndex, $values=array())
Sets values to the col at index $colIndex.
getHeader()
Returns/create eventually the header of the table.
setFocusable(bool $focusable)
getRow($rowIndex)
Retuns the row at $rowIndex.
getCell($row, $col)
Returns the cell (HtmlTD) at position $row,$col.
compile(JsUtils $js=NULL, &$view=NULL)
{{}BaseHtml::compile()}
onActiveRowChange($jsCode)
getPart($key)
Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot.
setColWidth($colIndex, $width)
compile_once(JsUtils $js=NULL, &$view=NULL)
colRight($colIndex)
Sets the col alignment to right.
colRightFromRight($colIndex)
Sets the col alignment to right.
getRowCount()
Returns the number of rows (TR)
getBody()
Returns/create eventually the body of the table.
onNewRow($callback)
The callback function called after the insertion of each row when fromDatabaseObjects is called callb...
setRowValues($rowIndex, $values=array())
Sets values to the row at index $rowIndex.
colAlign($colIndex, $function)
setColAlignmentFromRight($colIndex, $alignment)
addMergeRow($colCount, $value=null)
setCompileParts($parts=["tbody"])
Sets the parts of the Table to compile.
colCenter($colIndex)
Sets the col alignment to center.
setValues($values=array())
Sets the tbody values.
fromDatabaseObject($object, $function)
{}
getFooter()
Returns/create eventually the footer of the table.
addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false)
a table content (thead, tbody or tfoot)