Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

fabianmerino
Copy link
Contributor

πŸ”— Linked issue

❓ 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

This PR resolves an issue in the Table component where the colspan calculation was incorrect for grouped columns during loading and empty states. The fix ensures proper alignment and behavior of cells spanning multiple columns in these scenarios.

πŸ“ Checklist

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

@Copilot Copilot AI review requested due to automatic review settings August 26, 2025 06:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a colspan calculation issue in the Table component for loading and empty states when dealing with grouped columns. The fix ensures that cells properly span across all visible columns instead of only top-level column groups.

  • Updates colspan calculation to use tableApi.getAllLeafColumns().length instead of columns?.length
  • Affects both loading state row and empty state row
  • Ensures proper cell alignment when columns are grouped

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +493 to +499
<td :colspan="tableApi.getAllLeafColumns().length" :class="ui.loading({ class: props.ui?.loading })">
<slot name="loading" />
</td>
</tr>

<tr v-else>
<td :colspan="columns?.length" :class="ui.empty({ class: props.ui?.empty })">
<td :colspan="tableApi.getAllLeafColumns().length" :class="ui.empty({ class: props.ui?.empty })">
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The tableApi.getAllLeafColumns().length call could potentially throw an error if tableApi is undefined or null. Consider adding a null check or providing a fallback value to prevent runtime errors.

Copilot uses AI. Check for mistakes.

Comment on lines +493 to +499
<td :colspan="tableApi.getAllLeafColumns().length" :class="ui.loading({ class: props.ui?.loading })">
<slot name="loading" />
</td>
</tr>

<tr v-else>
<td :colspan="columns?.length" :class="ui.empty({ class: props.ui?.empty })">
<td :colspan="tableApi.getAllLeafColumns().length" :class="ui.empty({ class: props.ui?.empty })">
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The tableApi.getAllLeafColumns().length call could potentially throw an error if tableApi is undefined or null. Consider adding a null check or providing a fallback value to prevent runtime errors.

Copilot uses AI. Check for mistakes.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 26, 2025

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

commit: a779fd5

@benjamincanac
Copy link
Member

Do you have a reproduction of the issue? I think this is correct but I'm wondering if we should use getAllFlatColumns() instead of getAllLeafColumns() πŸ€”

@benjamincanac benjamincanac added the v3 #1289 label Aug 27, 2025
@benjamincanac benjamincanac changed the title fix(Table): colspan issue with grouped columns fix(Table): ensure colspan calc for loading and empty states Aug 27, 2025
@fabianmerino
Copy link
Contributor Author

Hi @benjamincanac,

Do you have a reproduction of the issue?

I've set up the reproduction to demonstrate this exact issue:
https://stackblitz.com/edit/nuxt-starter-mddvmdjv?file=app%2Fcomponents%2FTableExample.vue

I think this is correct but I'm wondering if we should use getAllFlatColumns() instead of getAllLeafColumns() πŸ€”

That's a really sharp observation, and I'm glad you brought it up. I actually had the exact same thought at first!

My initial impulse was to use getAllFlatColumns(), but I double-checked the documentation and found a key distinction that changed my mind.

Here’s what the docs say :

  • getAllFlatColumns(): "Returns all columns in the table flattened to a single level. This includes parent column objects throughout the hierarchy."
  • getAllLeafColumns(): "Returns all leaf-node columns in the table flattened to a single level. This does not include parent columns."

For the colspan, we need the count of only the final, rendered columns, which is exactly what getAllLeafColumns() provides.

You're right that getAllFlatColumns() seems to work without breaking the layout. I believe this happens because browsers are forgivingβ€”if a colspan is larger than the available columns, it's often implicitly capped at the maximum possible value. So while it works visually, it's technically based on an incorrect count.

Using getAllLeafColumns() ensures we are being semantically correct and more robust for the future.

Hope this clarifies my reasoning. Let me know what you think!

@benjamincanac
Copy link
Member

@fabianmerino Thanks a lot for the explanation 😊

@benjamincanac benjamincanac merged commit bdcc8c4 into nuxt:v3 Aug 31, 2025
6 checks passed
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.

2 participants