From afb3e36e0d6767b670142b55dc6087d7731f90a6 Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Wed, 2 Oct 2024 16:42:02 +0200 Subject: [PATCH] - added 'delete' for Table; --- .../FormField/components/Table/index.js | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/components/FormField/components/Table/index.js b/src/components/FormField/components/Table/index.js index 5967ec8..394c635 100644 --- a/src/components/FormField/components/Table/index.js +++ b/src/components/FormField/components/Table/index.js @@ -6,8 +6,9 @@ import { getCoreRowModel, flexRender, } from '@tanstack/react-table'; -import { pathOr, isEmpty } from 'ramda'; +import { pathOr, isEmpty, isNil } from 'ramda'; import { wrap } from 'object-path-immutable'; +import { Button } from 'primereact/button'; const Table = ({ fieldName, @@ -20,6 +21,8 @@ const Table = ({ }) => { const [stateFieldData, setStateFieldData] = useState([]); const [rowsData, setRowsData] = useState([]); + const [rowsDataLength, setRowsDataLength] = useState(0); + const [rowIndexToDelete, rowRowIndexToDelete] = useState(null); const [isDisabledNewRow, setIsDisabledNewRow] = useState(false); const [columns, setColumns] = useState([]); const table = useReactTable({ @@ -61,10 +64,14 @@ const Table = ({ setRowsData([...rowsData, obj]); } + const removeRow = (index) => { + rowRowIndexToDelete(index) + } + useEffect(() => { let shouldDisableNewRows = false; - const columns = stateFieldData.map((o) => { + let columns = stateFieldData.map((o) => { const item = { accessorKey: o.name, header: () => o.label, @@ -82,12 +89,45 @@ const Table = ({ }); setIsDisabledNewRow(shouldDisableNewRows); + + if (!shouldDisableNewRows && !isEmpty(columns)) { + columns.push({ + accessorKey: 'actions', + header: () => '', + footer: (props) => props.column.id, + cell: ({row: { index }}) =>