implemented proper functionality into table

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-27 15:00:17 +01:00
parent fcee82dd04
commit adb08d99fb
2 changed files with 26 additions and 1 deletions

View file

@ -27,7 +27,11 @@ export const uvalueColumns: ColumnDef<ComponentRecommendation>[] = [
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
onCheckedChange={(value) => {
if (value === true && !row.getIsSelected()) {
row.toggleSelected(true);
}
}}
aria-label="Select row"
/>
),

View file

@ -17,10 +17,20 @@ import {
} from "@/app/shadcn_components/ui/table";
import { ComponentRecommendation } from "@/app/db/schema/recommendations";
import { Dispatch, SetStateAction } from "react";
interface DataTableProps<T extends ComponentRecommendation> {
columns: ColumnDef<T>[];
data: T[];
defaultRowIndex: number;
rowSelection: {
[x: number]: boolean;
};
setRowSelection: Dispatch<
SetStateAction<{
[x: number]: boolean;
}>
>;
}
export default function RecommendationTable<T extends ComponentRecommendation>({
@ -37,6 +47,17 @@ export default function RecommendationTable<T extends ComponentRecommendation>({
columns,
getCoreRowModel: getCoreRowModel(),
onRowSelectionChange: setRowSelection,
// onRowSelectionChange: (RowSelectionState) => {
// // This is a hack but we cast RowSelectionState's type into a function so we can avoid typescript errors
// // but this allows us the functionality we need to prevent de-selecting already selected rows
// const RowSelectionStateCallable = RowSelectionState as Function;
// const rowSelection = Object(RowSelectionStateCallable());
// if (Object.keys(rowSelection).length !== 0) {
// console.log("in here?");
// setRowSelection(rowSelection);
// }
// },
enableMultiRowSelection: false,
enableSubRowSelection: false,
state: {