My Vue application calculates a table with rowspans by using an algorithm based on a configuration file. This allows the application to render columns (and maintain their order) dynamically, depending on the calculated result.
For example, see the code snippet below:
<template>
<table>
<thead>
<th>City</th>
<th>Inhabitant</th>
<th>House</th>
<th>Room</th>
</thead>
<tbody>
<tr v-for="(row, rowIndex) in tableMatrix" :key="rowIndex">
<template v-for="(cell, columnIndex) in row" :key="columnIndex">
<td v-if="cell.isCoveredByPreviousCell" style="display: none" />
<td v-else :rowspan="cell.rowspan ?? 1">
<template v-if="cell.content">
{{ cell.content }}
</template>
</td>
</template>
</tr>
</tbody>
</table>
</template>
<script setup lang="ts">
import { ref, Ref } from 'vue';
interface Cell { isCoveredByPreviousCell: boolean; rowspan: number; content?: string; }
type TableMatrix = Cell[][];
const tableMatrix: Ref<TableMatrix> = ref([
[
{ isCoveredByPreviousCell: false, rowspan: 5, content: "City 1" },
{ isCoveredByPreviousCell: false, rowspan: 4, content: "Inhabitant 1" },
{ isCoveredByPreviousCell: false, rowspan: 3, content: "House 1" },
{ isCoveredByPreviousCell: false, content: "Room 1" },
],
// more rows...
])
</script>
<style>
table, th, td { border-collapse: collapse; border: 1px solid black; }
</style>
The output generated is correct, but I'm looking for ways to enhance the visual clarity of the table design. Zebra striping doesn't work in this case. One approach could be adding dividing rows with fixed heights and different background colors or increasing the bottom border width of row cells. When attempting to add
tr { border-bottom: 5px solid black; }
, the outcome changes as shown here:
I'd appreciate any suggestions or ideas you might have to improve the presentation of the table.