Hi,
I tried the other approach. So I added the first_column_th=true
?parameter to the “Configuration parameters” field of the “TablePress table” block?and added this code:
add_action('init', 'add_tablepress_cell_attributes_filter');
function add_tablepress_cell_attributes_filter() {
// Use a high priority to ensure our filter runs last
add_filter('tablepress_cell_tag_attributes', 'tablepress_correct_scope_attributes', 100, 7);
}
/**
* Correct scope attributes for table headers
*
* @param array $tag_attributes Array of HTML attributes for the cell.
* @param string $table_id The current table ID.
* @param string $cell_content The cell content.
* @param int $row_idx The row number of the cell.
* @param int $col_idx The column number of the cell.
* @param int $colspan_row The number of combined columns for this cell.
* @param int $rowspan_col The number of combined rows for this cell.
* @return array Modified array of HTML attributes for the cell.
*/
function tablepress_correct_scope_attributes($tag_attributes, $table_id, $cell_content, $row_idx, $col_idx, $colspan_row, $rowspan_col) {
// Correct the scope attribute for the first cell in the header row
if ($row_idx == 1) {
$tag_attributes['scope'] = 'col'; // All cells in the header row should have scope="col"
}
// Set scope='row' for the first cell in each body row
elseif ($col_idx == 1) {
$tag_attributes['scope'] = 'row';
}
return $tag_attributes;
}
But now the first cell of the header row is set to scope ‘row’ while it should be scope ‘col’. The subsequent rows have their first cells set to scope ‘row’.
I made a test page here you see the output is:
<thead>
<tr class="row-1">
<th class="column-1" scope="row">Feature</th><th class="column-2" scope="col">Product A</th><th class="column-3" scope="col">Product B</th>
</tr>
</thead>
<tbody class="row-hover">
<tr class="row-2">
<th class="column-1" scope="row">Schaalbaarheid</th><td class="column-2">Hoog in de middenklassen</td><td class="column-3">Laag voor de lagere klasses</td>
</tr>
<tr class="row-3">
<th class="column-1" scope="row">Prijs</th><td class="column-2">2 euro</td><td class="column-3">3 euro</td>
</tr>
</tbody>
And I would want it to be one data table with three column header cells:
<thead>
<tr class="row-1">
<th class="column-1" scope="col">Feature</th><th class="column-2" scope="col">Product A</th><th class="column-3" scope="col">Product B</th>
</tr>
</thead>
<tbody class="row-hover">
<tr class="row-2">
<th class="column-1" scope="row">Schaalbaarheid</th><td class="column-2">Hoog in de middenklassen</td><td class="column-3">Laag voor de lagere klasses</td>
</tr>
<tr class="row-3">
<th class="column-1" scope="row">Prijs</th><td class="column-2">2 euro</td><td class="column-3">3 euro</td>
</tr>
</tbody>
-
This reply was modified 3 months, 4 weeks ago by handig.