Skip to content

Conversation

andr35
Copy link
Contributor

@andr35 andr35 commented Apr 11, 2025

πŸ”— Linked issue

Resolves #3865

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š 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.

This PR introduces the ability to:

  • Pass a function to the meta.class.td property of the columns prop to conditionally apply classes based on the cell's value.
  • Set the TanStack TableMeta property via props, and pass a function to the class.tr property of table's meta to conditionally apply classes based on the row's data.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

pkg-pr-new bot commented Apr 11, 2025

npm i https://pkg.pr.new/@nuxt/ui@3866

commit: f65b305

@benjamincanac benjamincanac added the v3 #1289 label Apr 16, 2025
interface ColumnMeta<TData extends RowData, TValue> {
class?: {
th?: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not handle function on th as well? πŸ€”

Copy link
Contributor Author

@andr35 andr35 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My use case involves highlighting a specific cell or row, for example, when a certain value in the row exceeds a threshold (e.g., "highlight the row in red if x > 10").
I don’t see a reason to modify the header cell, as it isn’t directly tied to any data.

That said, thinking about it now, there could be scenarios where it might be useful modifying the th. For instance, "highlight the header with a color gradient based on the average of the column values?"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the th should handle a function like td.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated also th.

@benjamincanac benjamincanac changed the title feat(Table): conditionally apply classes to tr and td elements feat(Table): conditionally apply classes to tr and td Apr 22, 2025
@benjamincanac benjamincanac merged commit 80dfa88 into nuxt:v3 Apr 22, 2025
5 checks passed
@benjamincanac
Copy link
Member

Thanks @andr35! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 #1289
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table: conditionally apply classes to tr and td elements
2 participants