Skip to content
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

TypeError: Cannot read properties of undefined (reading 'length') #59

Open
AbhinavSharma486 opened this issue Oct 2, 2024 · 1 comment

Comments

@AbhinavSharma486
Copy link

AbhinavSharma486 commented Oct 2, 2024

Screenshot 2024-10-03 140339
i am getting this error in my component : components\table\DataTable.tsx
And my Code is here :

"use client";

import {
ColumnDef,
flexRender,
getCoreRowModel,
getPaginationRowModel,
useReactTable,
} from "@tanstack/react-table";

import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { Button } from "../ui/button";
import Image from "next/image";

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
}

export function DataTable<TData, TValue>({
columns,
data,
}: DataTableProps<TData, TValue>) {
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
});

return (




{table.getHeaderGroups().map((headerGroup) => (

{headerGroup.headers.map((header) => {
return (

{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}

);
})}

))}


{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
className="shad-table-row"
>
{row.getVisibleCells().map((cell) => (

{flexRender(cell.column.columnDef.cell, cell.getContext())}

))}

))
) : (


No results.


)}

  <div className="table-actions">
    <Button
      variant="outline"
      size="sm"
      onClick={() => table.previousPage()}
      disabled={!table.getCanPreviousPage()}
      className="shad-gray-btn"
    >
      <Image
        src="/assets/icons/arrow.svg"
        width={24}
        height={24}
        alt="arrow"
      />
    </Button>
    <Button
      variant="outline"
      size="sm"
      onClick={() => table.nextPage()}
      disabled={!table.getCanNextPage()}
      className="shad-gray-btn"
    >
      <Image
        src="/assets/icons/arrow.svg"
        width={24}
        height={24}
        alt="arrow"
        className="rotate-180"
      />
    </Button>
  </div>
</div>

);
}

@klugeradoslaw
Copy link

Did you find the answer to this question? I have the same issue :(

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

No branches or pull requests

2 participants