nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - TableCell colSpan throwing error "Cell count must match column count"

Open renatodantas opened this issue 1 year ago • 3 comments

NextUI Version

2.1.13

Describe the bug

When I add the colSpan attribute to TableCell component to span some columns into one, I get the following error message:

Error: Cell count must match column count. Found 1 cells and 2 columns.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Below is a simple snippet of code that reproduces the problem:

<Table aria-label="Test">
  <TableHeader columns={columns}>
    <TableColumn>Column 1</TableColumn>
    <TableColumn>Column 2</TableColumn>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell colSpan={2}>
        Some message
      </TableCell>
    </TableRow>
  </TableBody>
</Table>

Expected behavior

The table rendered with the columns spanned correctly.

Screenshots or Videos

Operating System Version

Linux & MacOS

Browser

Chrome

EDIT:

I believe this issue is related (and depends on) https://github.com/adobe/react-spectrum/issues/5334.

renatodantas avatar Oct 17 '23 19:10 renatodantas

wont the colSpan prop be present in TableColumn (in the header) ? idk, but im curious.

Edit: It seems to be a bug with @react-stately/table package, as it is not including the colSpan values in its validation

awkward-minion avatar Oct 31 '23 08:10 awkward-minion

Still not working, any alternative solution?

IraiDev avatar Dec 12 '23 19:12 IraiDev

I have found this workaround, hope it helps!

"use client";
import React from "react";
import {
  Table,
  TableHeader,
  TableColumn,
  TableBody,
  TableRow,
  TableCell,
} from "@nextui-org/react";

export default function App() {
  return (
    <Table aria-label="Example static collection table">
      <TableHeader>
        <TableColumn>NAME</TableColumn>
        <TableColumn>ROLE</TableColumn>
        <TableColumn>STATUS</TableColumn>
      </TableHeader>
      <TableBody>
        <TableRow key="1">
          <TableCell>Tony Reichert</TableCell>
          <TableCell>CEO</TableCell>
          <TableCell>Active</TableCell>
        </TableRow>
        <TableRow key="2">
          <TableCell aria-colspan={3} colSpan={3} className="bg-red-200">
            Zoey Lang
          </TableCell>
          <TableCell className="hidden"> </TableCell>
          <TableCell className="hidden"> </TableCell>
        </TableRow>
        <TableRow key="3">
          <TableCell>Jane Fisher</TableCell>
          <TableCell>Senior Developer</TableCell>
          <TableCell>Active</TableCell>
        </TableRow>
      </TableBody>
    </Table>
  );
}

This is how it looks like: Captura de pantalla 2024-01-28 a la(s) 14 05 56

Armandotrsg avatar Jan 28 '24 20:01 Armandotrsg

I have a similar question but for table headers. Is there a workaround to create a table header like this in nextui?

I have found this workaround, hope it helps!

"use client";
import React from "react";
import {
  Table,
  TableHeader,
  TableColumn,
  TableBody,
  TableRow,
  TableCell,
} from "@nextui-org/react";

export default function App() {
  return (
    <Table aria-label="Example static collection table">
      <TableHeader>
        <TableColumn>NAME</TableColumn>
        <TableColumn>ROLE</TableColumn>
        <TableColumn>STATUS</TableColumn>
      </TableHeader>
      <TableBody>
        <TableRow key="1">
          <TableCell>Tony Reichert</TableCell>
          <TableCell>CEO</TableCell>
          <TableCell>Active</TableCell>
        </TableRow>
        <TableRow key="2">
          <TableCell aria-colspan={3} colSpan={3} className="bg-red-200">
            Zoey Lang
          </TableCell>
          <TableCell className="hidden"> </TableCell>
          <TableCell className="hidden"> </TableCell>
        </TableRow>
        <TableRow key="3">
          <TableCell>Jane Fisher</TableCell>
          <TableCell>Senior Developer</TableCell>
          <TableCell>Active</TableCell>
        </TableRow>
      </TableBody>
    </Table>
  );
}

This is how it looks like: Captura de pantalla 2024-01-28 a la(s) 14 05 56

The above solution may work well, but I have a similar question for table headers. Is there a workaround to create a table header like this in NextUI?

image

zshnrg avatar Jul 22 '24 09:07 zshnrg