Replies: 5 comments 14 replies
-
I have same question |
Beta Was this translation helpful? Give feedback.
-
I believe you are able to pass additional object properties in the second argument to Edit: One way to handle the type definition issue if you are using TypeScript is to create a custom context type and cast the argument for the import { createColumnHelper, CellContext as TanCellContext } from "@tanstack/react-table";
type CellContext<TData extends RowData, TValue> = TanCellContext<
TData,
TValue
> & {
additionalProp: string;
};
type RowType = { myProp: string; };
const columnHelper = createColumnHelper<RowType>();
const columns = [
columnHelper.accessor("myProp", {
cell: (info: unknown) => {
const infoCasted = info as CellContext<RowType, string>;
return <p>{infoCasted.getValue()}: {infoCasted.additionalProp}</p>;
},
}),
]; |
Beta Was this translation helpful? Give feedback.
-
For anyone else looking for a different way, the package exposes an argument called "meta" which can be extended. Please check here, |
Beta Was this translation helpful? Give feedback.
-
I ended up using react's useContext() to access my data inside the target component |
Beta Was this translation helpful? Give feedback.
-
Here's how I solved this without context or extra type declarations: Define the columns inside a function which accepts params and pass those along to your custom cell component const createColumns = ({ onActionClick }: { onActionClick: () => void }) =>
[
<..other column definitions..>
{
id: "actions",
cell: ({ row }) => {
return (
<button onClick={onActionClick}>Edit</button>
);
},
},
] satisfies ColumnDef<YourTableDataType>[]; Call the function in your component and pass the params you want const YourComponent = () => {
const [state, setState] = useState()
// Would probably be good to wrap this in useMemo
const columns = createColumns({onActionClick: () => setState(true)})
const table = useReactTable({
columns
...
})
...
} |
Beta Was this translation helpful? Give feedback.
-
How in v8 pass props from cell renderer to custom made input?
Beta Was this translation helpful? Give feedback.
All reactions