Given a Vue app based on Vuetify using the table component. When using this setup
<template>
<v-app>
<v-main>
<v-container fluid>
<v-table>
<thead>
<tr>
<th>Col 1</th>
<th>Txt</th>
<th>Checkbox Column</th>
<th>Select ( plain txt )</th>
<th>Chips</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>
<v-text-field label="Label goes here" model-value="some text goes here"></v-text-field>
</td>
<td>
<v-checkbox label="Label for checkbox goes here" :model-value="true"></v-checkbox>
</td>
<td>
<v-select label="Select with plain text" :items="[1, 2, 3]" :model-value="1"></v-select>
</td>
<td>
<v-select label="Select with chips" multiple chips :items="['aaaaaaa', 'bbbbbbbbb', 'Some more items here']" :model-value="['Some more items here']"></v-select>
</td>
</tr>
</tbody>
</v-table>
</v-container>
</v-main>
</v-app>
</template>
The table looks fine on large screens
but the table breaks on smaller screens
This table should work for desktops ( no need for responsive mobile support ) and has a dynamic amount of columns ( at least more than 20 ). I want each column ( and its elements ) to expand to a "human readable" width. So no label, chip, text etc. should be cut off. It’s perfectly fine if the horizontal scrollbar is huge. But I would like to avoid using a hardcoded columns width because each column should only take the space it needs to display its content.
I hope it’s not a Vuetify problem because the table relies on basic HTML but I don’t know how to fix it via CSS.
3
Answers
As an alternative to Rohìt Jíndals answer, I found a temporary workaround to prevent elements from cutting off content.
It is not a perfect solution, as gigantic labels and chips still won't fit.
But now no content is cut off. Demo
set
white-space: nowrap;
property fortd
if the dynamic content is not lengthy plain text or if you do not have an issue with presenting it on single line.Example code base is added for reference.
As you are using Vuetify 3
<v-table>
component and it is just a simple wrapper component around the HTML<table>
element. I did not see any inbuiltprops
to setting the width for the table as well as for the columns. Hence, you can only achieve this at this point of time by applying the custom width ontd
andth
with the help of CSS.Live Demo :