mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-49399 core: Add ability to specify a header col
This commit is contained in:
parent
4c5b60a0f9
commit
702123a1dd
@ -57,6 +57,11 @@ class flexible_table {
|
||||
var $attributes = array();
|
||||
var $headers = array();
|
||||
|
||||
/**
|
||||
* @var string A column which should be considered as a header column.
|
||||
*/
|
||||
protected $headercolumn = null;
|
||||
|
||||
/**
|
||||
* @var string For create header with help icon.
|
||||
*/
|
||||
@ -429,6 +434,17 @@ class flexible_table {
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a specific column as being a table header using the column name defined in define_columns.
|
||||
*
|
||||
* Note: Only one column can be a header, and it will be rendered using a th tag.
|
||||
*
|
||||
* @param string $column
|
||||
*/
|
||||
public function define_header_column(string $column) {
|
||||
$this->headercolumn = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a help icon for the header
|
||||
*
|
||||
@ -1098,6 +1114,18 @@ class flexible_table {
|
||||
foreach ($row as $index => $data) {
|
||||
$column = $colbyindex[$index];
|
||||
|
||||
$attributes = [
|
||||
'class' => "cell c{$index}" . $this->column_class[$column],
|
||||
'id' => "{$rowid}_c{$index}",
|
||||
'style' => $this->make_styles_string($this->column_style[$column]),
|
||||
];
|
||||
|
||||
$celltype = 'td';
|
||||
if ($this->headercolumn && $column == $this->headercolumn) {
|
||||
$celltype = 'th';
|
||||
$attributes['scope'] = 'row';
|
||||
}
|
||||
|
||||
if (empty($this->prefs['collapse'][$column])) {
|
||||
if ($this->column_suppress[$column] && $suppress_lastrow !== NULL && $suppress_lastrow[$index] === $data) {
|
||||
$content = ' ';
|
||||
@ -1108,10 +1136,7 @@ class flexible_table {
|
||||
$content = ' ';
|
||||
}
|
||||
|
||||
$html .= html_writer::tag('td', $content, array(
|
||||
'class' => 'cell c' . $index . $this->column_class[$column],
|
||||
'id' => $rowid . '_c' . $index,
|
||||
'style' => $this->make_styles_string($this->column_style[$column])));
|
||||
$html .= html_writer::tag($celltype, $content, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user