47 parent::__construct(
$identifier,
"table",
"ui table");
48 $this->content = array();
50 $this->_variations = [
55 $this->_compileParts = [
60 $this->_afterCompileEvents = [];
70 if (\array_key_exists($key, $this->content) ===
false) {
72 if ($key !==
"tbody") {
73 $this->content[$key]->setRowCount(1, $this->_colCount);
76 return $this->content[$key];
80 if (isset($this->content[
"thead"])) {
81 return $this->content[
"thead"];
83 return $this->content[
"tbody"];
101 return $this->
getPart(
"tbody")->count();
110 return $this->
getPart(
"thead");
119 return $this->
getPart(
"tfoot");
129 return \array_key_exists($key, $this->content) ===
true;
139 $this->_colCount = $colCount;
140 return $this->
getBody()->setRowCount($rowCount, $colCount);
151 return $this->
getBody()->getCell($row, $col);
161 return $this->
getBody()->getRow($rowIndex);
170 public function addRow($values = array()) {
171 $row = $this->
getBody()->addRow($this->_colCount);
172 $row->setValues(\array_values($values));
182 return $this->
getBody()->newRow($this->_colCount);
193 $this->
getBody()->setValues($values);
204 return $this->
getHeader()->setValues($values);
214 return $this->
getFooter()->setValues($values);
225 $this->
getBody()->setColValues($colIndex, $values);
237 $this->
getBody()->setRowValues($rowIndex, $values);
242 return $this->
getBody()->addColVariations($colIndex, $variations);
252 return $this->
colAlign($colIndex,
"colCenter");
262 return $this->
colAlign($colIndex,
"colRight");
272 return $this->
colAlign($colIndex,
"colLeft");
282 return $this->
colAlign($colIndex,
"colCenterFromRight");
292 return $this->
colAlign($colIndex,
"colRightFromRight");
302 return $this->
colAlign($colIndex,
"colLeftFromRight");
306 switch ($alignment) {
308 $function =
"colLeft";
312 $function =
"colRight";
316 $function =
"colCenter";
320 $function =
"colLeft";
322 $this->
colAlign($colIndex, $function);
327 switch ($alignment) {
329 $function =
"colLeftFromRight";
333 $function =
"colRightFromRight";
337 $function =
"colCenterFromRight";
341 $function =
"colLeftFromRight";
343 $this->
colAlign($colIndex, $function);
348 if (\is_array($colIndex)) {
349 foreach ($colIndex as $cIndex) {
350 $this->
colAlign($cIndex, $function);
354 $this->
getHeader()->$function($colIndex);
356 $this->
getBody()->$function($colIndex);
371 $this->
getBody()->conditionalCellFormat($callback, $format);
385 $this->
getBody()->conditionalRowFormat($callback, $format);
396 $this->
getBody()->applyCells($callback);
407 $this->
getBody()->applyRows($callback);
418 if (\
sizeof($this->_compileParts) < 3) {
419 $this->_template =
"%content%";
423 return parent::compile($js, $view);
427 parent::compile_once($js, $view);
429 $this->
addEvent(
"execute",
"$('#" . $this->identifier .
"').tablesort().data('tablesort').sort($('th.default-sort'));");
440 $result = $function($object);
441 if (\is_array($result)) {
442 $result = $this->
addRow($function($object));
444 $result = $this->
getBody()->_addRow($result);
446 if (isset($this->_afterCompileEvents[
"onNewRow"])) {
447 if (\is_callable($this->_afterCompileEvents[
"onNewRow"]))
448 $this->_afterCompileEvents[
"onNewRow"]($result, $object);
463 $this->_compileParts = $parts;
469 $this->
getPart(
"tbody")->refreshTR();
475 $js->exec(
'$("#' . $this->identifier .
' tfoot").replaceWith("' . \addslashes($this->_footer) .
'");',
true);
480 if (! $this->_runned) {
481 if (isset($this->_activeRowSelector)) {
482 $this->_activeRowSelector->run();
486 if (isset($this->_footer))
487 $this->_footer->run($js);
488 $this->_runned =
true;
500 $this->_afterCompileEvents[
"onNewRow"] = $callback;
513 $this->_activeRowSelector =
new ActiveRow($this, $class, $event, $multiple);
518 if (isset($this->_activeRowSelector)) {
519 return $this->_activeRowSelector->getClass();
525 return isset($this->_activeRowSelector);
529 if (isset($this->content[
"thead"])) {
530 $this->content[
"thead"]->hideColumn($colIndex);
532 $this->content[
"tbody"]->hideColumn($colIndex);
533 if (isset($this->content[
"tfoot"])) {
534 $this->content[
"tfoot"]->hideColumn($colIndex);
541 if ($part !== null && $part->count() > 0)
542 $part->getCell(0, $colIndex)->setWidth($width);
548 if ($part !== null && $part->count() > 0) {
549 $count = $part->getColCount();
550 if (! \is_array($widths)) {
551 $widths = \array_fill(0, $count, $widths);
553 $max = \min(\
sizeof($widths), $count);
554 for ($i = 0; $i < $max; $i ++) {
555 $part->getCell(0, $i)->setWidth($widths[$i]);
563 $body->mergeIdentiqualValues($colIndex, $function);
584 $this->
on(
"activeRowChange", $jsCode);
589 return $this->
getBody()->addMergeRow($colCount, $value);
597 $this->
getBody()->setFocusable($focusable);
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.
addRow($values=array())
Adds a new row and sets $values to his cols.
newRow()
adds and returns a new row
colRightFromRight($colIndex)
Sets the col alignment to right.
colAlign($colIndex, $function)
applyRows($callback)
Applies a callback function on each row.
setInnerScript($_innerScript)
onActiveRowChange($jsCode)
mergeIdentiqualValues($colIndex, $function="strip_tags")
compile_once(JsUtils $js=NULL, &$view=NULL)
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
getHeader()
Returns/create eventually the header of the table.
propertyContains($propertyName, $value)
A class for row selection in Table or DataTable.
setCompileParts($parts=["tbody"])
Sets the parts of the Table to compile.
colRight($colIndex)
Sets the col alignment to right.
getFooter()
Returns/create eventually the footer of the table.
setFocusable(bool $focusable)
applyCells($callback)
Applies a callback function on each cell.
setRowValues($rowIndex, $values=array())
Sets values to the row at index $rowIndex.
getCell($row, $col)
Returns the cell (HtmlTD) at position $row,$col.
a table content (thead, tbody or tfoot)
colCenter($colIndex)
Sets the col alignment to center.
setColWidth($colIndex, $width)
setColAlignment($colIndex, $alignment)
setColAlignmentFromRight($colIndex, $alignment)
colLeftFromRight($colIndex)
Sets col alignment to left.
conditionalRowFormat($callback, $format)
Applies a format on each row when $callback returns true.
compile(JsUtils $js=NULL, &$view=NULL)
{}
setHeaderValues($values=array())
Sets the header values.
setColValues($colIndex, $values=array())
Sets values to the col at index $colIndex.
setFooterValues($values=array())
Sets the footer values.
Semantic HTML Table component.
Base class for Semantic double elements.
getRow($rowIndex)
Retuns the row at $rowIndex.
onNewRow($callback)
The callback function called after the insertion of each row when fromDatabaseObjects is called callb...
fromDatabaseObject($object, $function)
{}
addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false)
colCenterFromRight($colIndex)
Sets the col alignment to center.
__construct($identifier, $rowCount, $colCount)
hasPart($key)
Checks if the part corresponding to $key exists.
setValues($values=array())
Sets the tbody values.
getBody()
Returns/create eventually the body of the table.
getRowCount()
Returns the number of rows (TR)
colLeft($colIndex)
Sets col alignment to left.
addMergeRow($colCount, $value=null)
static sortAssociative($array, $sortedKeys=array())
setRowCount($rowCount, $colCount)
getPart($key)
Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot...