TanStackT
TanStack3y ago
3 replies
progressive-amaranth

row.getCanExpand() always false on expanding table

Im trying to make a expandable table but when I try customizing the cell for the expandable column, the row.getCanExpand() always returns false. I find no way to make it return true

This is my comun def

export type BaseOrderData = {
    id?: string | null;
    createdAt?: string | null;
    status?: string | null;
    shippingMethod?: string | null;
    address?: string | null;
    totalProducts?: number | null;
    total?: number | null;
};

export const columns: ColumnDef<BaseOrderData>[] = [
    {
        accessorKey: "id",
        header: "ID",
        cell: ({ row }) => {
            return (row.getCanExpand() ? (
                <button
                    {...{
                        onClick: row.getToggleExpandedHandler(),
                        style: { cursor: 'pointer' },
                    }}
                >
                    {row.getIsExpanded() ? '👇' : '👉'}
                </button>) : 'nope')
        }
    },
    {
        accessorKey: "createdAt",
        header: "Fecha",
    },
    {
        accessorKey: "status",
        header: "Estado",
    },
    {
        accessorKey: "shippingMethod",
        header: "Método de envío",
    },
    {
        accessorKey: "address",
        header: "Dirección",
    },
    {
        accessorKey: "totalProducts",
        header: "Total productos",
    },
    {
        accessorKey: "total",
        header: "Total",
    },
];


And this is what I am passing to my useReactTable method
    const [expanded, setExpanded] = useState<ExpandedState>({});

    const table = useReactTable({
        data,
        columns,
        getCoreRowModel: getCoreRowModel(),
        getExpandedRowModel: getExpandedRowModel(),
        onExpandedChange: setExpanded,
        state: {
            expanded,
        },
        debugTable: true
    });
Was this page helpful?