-
objective: so const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onSortingChange: setSorting,
getSortedRowModel: getSortedRowModel(),
onColumnFiltersChange: setColumnFilters,
onGlobalFilterChange: setGlobalFilter,
getFilteredRowModel: getFilteredRowModel(),
onRowSelectionChange: setRowSelection,
state: {
sorting,
columnFilters,
globalFilter,
rowSelection,
},
meta: {
updateData: (rowIndex: number, columnId: string, value: string) => {
setData((old) =>
old.map((row, index) => {
if (index === rowIndex) {
return {
...old[rowIndex],
[columnId]: value,
};
}
return row;
})
);
}, in my cell component interface ITableCellProps {
getValue: () => any;
row: Row<any>;
column: Column<any>;
table: Table<any>;
}
export const TableCell = ({
getValue,
row,
column,
table,
}: ITableCellProps) => {
const initialValue = getValue();
const [value, setValue] = useState("");
useEffect(() => {
setValue(initialValue);
}, [initialValue]);
const onBlur = () => {
if (
table.options.meta &&
typeof table.options.meta.updateData === "function"
) {
(table.options.meta.updateData as Function)(row.index, column.id, value);
} else {
console.error("updateData method is not available");
}
}; on I tried https://tanstack.com/table/v8/docs/api/core/table#meta and declare in my types declare module "@tanstack/table-core" {
interface TableMeta<TData extends RowData> {
updateData?: (rowIndex: number, columnId: string, value: string) => void;
toggleAllBoolean?: (columnId: string, value: boolean) => void;
changeAllOptions?: (columnId: string, value: string | number) => void;
getIsAllTrue?: (columnId: string) => boolean;
getIsSomeTrue?: (columnId: string) => boolean;
}
} but then I got a bunch of error
so, to properly add custom function table? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
vatoer
Mar 14, 2024
Replies: 1 comment 3 replies
-
my bad it should be "@tanstack/react-table" - declare module "@tanstack/table-core" {
+ import { RowData } from "@tanstack/react-table";
+ declare module "@tanstack/react-table" {
interface TableMeta<TData extends RowData> {
updateData?: (rowIndex: number, columnId: string, value: string) => void;
toggleAllBoolean?: (columnId: string, value: boolean) => void;
changeAllOptions?: (columnId: string, value: string | number) => void;
getIsAllTrue?: (columnId: string) => boolean;
getIsSomeTrue?: (columnId: string) => boolean;
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
vatoer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my bad it should be "@tanstack/react-table"