diff --git a/lib/tablelib.php b/lib/tablelib.php index b9b593a7ffa..7aab424dc6b 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -1143,6 +1143,12 @@ class flexible_table { foreach ($row as $index => $data) { $column = $colbyindex[$index]; + $columnattributes = $this->columnsattributes[$column] ?? []; + if (isset($columnattributes['class'])) { + $this->column_class($column, $columnattributes['class']); + unset($columnattributes['class']); + } + $attributes = [ 'class' => "cell c{$index}" . $this->column_class[$column], 'id' => "{$rowid}_c{$index}", @@ -1155,7 +1161,7 @@ class flexible_table { $attributes['scope'] = 'row'; } - $attributes += $this->columnsattributes[$column] ?? []; + $attributes += $columnattributes; if (empty($this->prefs['collapse'][$column])) { if ($this->column_suppress[$column] && $suppresslastrow !== null && $suppresslastrow[$index] === $data) { diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 35fde2df642..d007f8a840a 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -74,6 +74,7 @@ information provided here is intended especially for developers. action in the modal body like ticking a checkbox or selecting an element. * Course module indentation has been recovered for course format using components via Move right/left feature. Course formats using components will be allowed to use one level indentation only. +* The method `flexible_table::set_columnsattributes` now can be used with 'class' key to add custom classes to the DOM. === 4.1 === diff --git a/reportbuilder/classes/external/custom_report_exporter.php b/reportbuilder/classes/external/custom_report_exporter.php index 9fb6f60e8ad..b3e9f9fb6c0 100644 --- a/reportbuilder/classes/external/custom_report_exporter.php +++ b/reportbuilder/classes/external/custom_report_exporter.php @@ -100,6 +100,7 @@ class custom_report_exporter extends persistent_exporter { ], 'multiple' => true, ], + 'classes' => ['type' => PARAM_TEXT], 'editmode' => ['type' => PARAM_BOOL], 'sidebarmenucards' => [ 'type' => custom_report_column_cards_exporter::read_properties_definition(), @@ -155,10 +156,16 @@ class custom_report_exporter extends persistent_exporter { if ($filterspresent) { $filtersform = $this->generate_filters_form()->render(); } - // Get the report attributes. + + // Get the report classes and attributes. + $reportattributes = $report->get_attributes(); + if (isset($reportattributes['class'])) { + $classes = $reportattributes['class']; + unset($reportattributes['class']); + } $attributes = array_map(static function($key, $value): array { return ['name' => $key, 'value' => $value]; - }, array_keys($report->get_attributes()), $report->get_attributes()); + }, array_keys($reportattributes), $reportattributes); } // If we are editing we need all this information for the template. @@ -186,6 +193,7 @@ class custom_report_exporter extends persistent_exporter { 'filterspresent' => $filterspresent, 'filtersform' => $filtersform, 'attributes' => $attributes, + 'classes' => $classes ?? '', 'editmode' => $this->editmode, 'javascript' => '', ] + $editordata; diff --git a/reportbuilder/classes/external/system_report_exporter.php b/reportbuilder/classes/external/system_report_exporter.php index cabfa2a5457..4a2e2854bec 100644 --- a/reportbuilder/classes/external/system_report_exporter.php +++ b/reportbuilder/classes/external/system_report_exporter.php @@ -77,6 +77,7 @@ class system_report_exporter extends persistent_exporter { ], 'multiple' => true, ], + 'classes' => ['type' => PARAM_TEXT], ]; } @@ -116,10 +117,15 @@ class system_report_exporter extends persistent_exporter { $filtersform->set_data_for_dynamic_submission(); } - // Get the report attributes. + // Get the report classes and attributes. + $sourceattributes = $source->get_attributes(); + if (isset($sourceattributes['class'])) { + $classes = $sourceattributes['class']; + unset($sourceattributes['class']); + } $attributes = array_map(static function($key, $value): array { return ['name' => $key, 'value' => $value]; - }, array_keys($source->get_attributes()), $source->get_attributes()); + }, array_keys($sourceattributes), $sourceattributes); return [ 'table' => $output->render($table), @@ -128,6 +134,7 @@ class system_report_exporter extends persistent_exporter { 'filtersapplied' => $source->get_applied_filter_count(), 'filtersform' => $filterspresent ? $filtersform->render() : '', 'attributes' => $attributes, + 'classes' => $classes ?? '', ]; } } diff --git a/reportbuilder/templates/report.mustache b/reportbuilder/templates/report.mustache index ff28539a42f..65be77cb595 100644 --- a/reportbuilder/templates/report.mustache +++ b/reportbuilder/templates/report.mustache @@ -34,7 +34,7 @@ "filtersform": "form" } }} -