I am using React Table and I am trying to make my table clickable to link to a page different for reach row. but now that i have no error screen my column isn't displaying any data for any of the rows.
(when i take away the
Cell: (props) =>
linkTo(`ticket/[id]`, props.ticket_title, `ticket/${props.ticket_id}`),
everything goes back to normal)
this is my column file:
import { linkTo } from '../utils/linkTo';
import { tableFormatted } from '../utils/tableFormatted';
export const TICKET_COLUMNS = [
{
Header: 'Ticket Number',
accessor: 'ticket_id',
},
{
Header: 'Title',
accessor: (d) => `${d.ticket_title} ${d.ticket_id}`,
Cell: (props) =>
linkTo(`ticket/[id]`, props.ticket_title, `ticket/${props.ticket_id}`),
},
{
Header: 'Description',
accessor: 'ticket_text',
},
{
Header: 'Priority',
accessor: 'ticket_priority',
Cell: (props) => tableFormatted(props.value),
},
{
Header: 'Status',
accessor: 'ticket_status',
Cell: (props) => tableFormatted(props.value),
},
{
Header: 'Type',
accessor: 'ticket_type',
Cell: (props) => tableFormatted(props.value),
},
];
This is my linkTo function that i use to try an make the cell clickable:
import { Link } from '@chakra-ui/layout';
import NextLink from 'next/link';
export const linkTo = (
linkInput: string,
children: string,
asInput?: string
) => {
if (asInput) {
return (
<>
<NextLink href={linkInput} as={asInput}>
<Link>{children}</Link>
</NextLink>
</>
);
} else {
return (
<>
<NextLink href={linkInput}>
<td>{children}</td>
</NextLink>
</>
);
}
};
This is the table itself, though i don't think the table is the problem, but who knows, certainly not me haha.:
import React, { useMemo } from 'react';
import { Table } from 'react-bootstrap';
import { Column, useGlobalFilter, useTable } from 'react-table';
import { GlobalFilter } from './GlobalFilter';
type TestTableProps = {
dataInput: any[];
columnInput: any[];
userInput?: any;
};
export const TestTable: React.FC<TestTableProps> = ({
dataInput,
columnInput,
userInput,
}) => {
const meData = userInput ? userInput : null;
const isData = dataInput ? dataInput : [{}];
const columns = useMemo<Column<object>[]>(() => columnInput, []);
const data = useMemo(() => isData, [isData]);
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
state,
setGlobalFilter,
} = useTable(
{
columns,
data,
},
useGlobalFilter
);
const { globalFilter } = state;
if (!isData) {
return <>no data</>;
} else {
return (
<>
<GlobalFilter filter={globalFilter} setFilter={setGlobalFilter} />
<Table
{...getTableProps()}
striped
bordered
hover
responsive
variant="dark"
>
<thead>
{headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column) => (
<th {...column.getHeaderProps()}>
{column.render('Header')}
</th>
))}
</tr>
))}
</thead>
<tbody {...getTableBodyProps()}>
{rows.map((row) => {
prepareRow(row);
return (
<tr {...row.getRowProps()}>
{row.cells.map((cell) => {
return (
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
);
})}
</tr>
);
})}
</tbody>
</Table>
</>
);
}
};