-
Notifications
You must be signed in to change notification settings - Fork 763
Table: conditionally apply classes to tr and td elements #3865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I was invited to "Start your project using the nuxt/starter#ui template with Nuxt UI pre-configured." (from https://ui.nuxt.com/getting-started/installation/nuxt). I did that, and found myself using Nuxt-UI V3.x. Lots of changes, of course, but everything seemed good until I crashed head-on into this problem. I should have noticed that a whole page of examples for Table had no row styles. Thanks for your work and do know that row style is critical for every app I've ever written that uses tables. |
I updated to Nuxt/UI 3.1.0 and read the table documentation which says:
The tanstack doc didn't help either. I was unable to get anything working. Could someone add a working example to the table component doc? Preferably this would include data-dependent styling like "all rows with column A = bad get pink background". Thanks again. |
I tired Nuxt UI 3.1.0 and I confirm that the the feature works. Here is a code snippet showing what add to <template>
<!-- 1. Provide "tableMeta" to UTable -->
<UTable
:columns="columns"
:data="rows"
:meta="tableMeta"
>
<!-- ... -->
</UTable>
</template>
<script setup lang="ts">
import type { TableRow } from "@nuxt/ui";
// 2. Use "tableMeta" to customize table's tr
const tableMeta = {
class: {
tr: (row: TableRow<{ value: number }>) => {
return row.original.value > 10 ? "bg-red-500" : "";
},
},
};
</script> |
Thanks. Will try it tomorrow morning. |
Description
Description
In Nuxt UI v3, there is currently no way to apply custom styles or classes to individual table rows or cells. Additionally, it is not possible to dynamically set classes based on specific criteria, for example, the value of data displayed in a given cell.
In contrast, this feature was available in Nuxt UI v2, as documented in the official documentation. In that version, custom classes could be applied by simply adding a
class
property to a specific row's data:Additional context
No response
The text was updated successfully, but these errors were encountered: