mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
implemented proper functionality into table
This commit is contained in:
parent
fcee82dd04
commit
adb08d99fb
2 changed files with 26 additions and 1 deletions
|
|
@ -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"
|
||||
/>
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue