Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions src/components/CippTable/CippDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const CippDataTable = (props) => {
const [offcanvasVisible, setOffcanvasVisible] = useState(false);
const [offCanvasData, setOffCanvasData] = useState({});
const [offCanvasRowIndex, setOffCanvasRowIndex] = useState(0);
const [filteredRows, setFilteredRows] = useState([]);
const [customComponentData, setCustomComponentData] = useState({});
const [customComponentVisible, setCustomComponentVisible] = useState(false);
const [actionData, setActionData] = useState({ data: {}, action: {}, ready: false });
Expand Down Expand Up @@ -293,7 +294,12 @@ export const CippDataTable = (props) => {
? ({ row }) => ({
onClick: () => {
setOffCanvasData(row.original);
setOffCanvasRowIndex(row.index);
// Find the index of this row in the filtered rows
const filteredRowsArray = table.getFilteredRowModel().rows;
const indexInFiltered = filteredRowsArray.findIndex(
(r) => r.original === row.original
);
setOffCanvasRowIndex(indexInFiltered >= 0 ? indexInFiltered : 0);
setOffcanvasVisible(true);
},
sx: {
Expand Down Expand Up @@ -455,7 +461,12 @@ export const CippDataTable = (props) => {
onClick={() => {
closeMenu();
setOffCanvasData(row.original);
setOffCanvasRowIndex(row.index);
// Find the index of this row in the filtered rows
const filteredRowsArray = table.getFilteredRowModel().rows;
const indexInFiltered = filteredRowsArray.findIndex(
(r) => r.original === row.original
);
setOffCanvasRowIndex(indexInFiltered >= 0 ? indexInFiltered : 0);
setOffcanvasVisible(true);
}}
>
Expand All @@ -471,7 +482,12 @@ export const CippDataTable = (props) => {
onClick={() => {
closeMenu();
setOffCanvasData(row.original);
setOffCanvasRowIndex(row.index);
// Find the index of this row in the filtered rows
const filteredRowsArray = table.getFilteredRowModel().rows;
const indexInFiltered = filteredRowsArray.findIndex(
(r) => r.original === row.original
);
setOffCanvasRowIndex(indexInFiltered >= 0 ? indexInFiltered : 0);
setOffcanvasVisible(true);
}}
>
Expand Down Expand Up @@ -688,6 +704,19 @@ export const CippDataTable = (props) => {
}
}, [table.getSelectedRowModel().rows]);

useEffect(() => {
// Update filtered rows whenever table filtering/sorting changes
if (table && table.getFilteredRowModel) {
const rows = table.getFilteredRowModel().rows;
setFilteredRows(rows.map((row) => row.original));
}
}, [
table,
table.getState().columnFilters,
table.getState().globalFilter,
table.getState().sorting,
]);

useEffect(() => {
//check if the simplecolumns are an array,
if (Array.isArray(simpleColumns) && simpleColumns.length > 0) {
Expand Down Expand Up @@ -769,20 +798,20 @@ export const CippDataTable = (props) => {
customComponent={offCanvas?.customComponent}
onNavigateUp={() => {
const newIndex = offCanvasRowIndex - 1;
if (newIndex >= 0 && memoizedData && memoizedData[newIndex]) {
if (newIndex >= 0 && filteredRows && filteredRows[newIndex]) {
setOffCanvasRowIndex(newIndex);
setOffCanvasData(memoizedData[newIndex]);
setOffCanvasData(filteredRows[newIndex]);
}
}}
onNavigateDown={() => {
const newIndex = offCanvasRowIndex + 1;
if (memoizedData && newIndex < memoizedData.length) {
if (filteredRows && newIndex < filteredRows.length) {
setOffCanvasRowIndex(newIndex);
setOffCanvasData(memoizedData[newIndex]);
setOffCanvasData(filteredRows[newIndex]);
}
}}
canNavigateUp={offCanvasRowIndex > 0}
canNavigateDown={memoizedData && offCanvasRowIndex < memoizedData.length - 1}
canNavigateDown={filteredRows && offCanvasRowIndex < filteredRows.length - 1}
{...offCanvas}
/>
{/* Render custom component */}
Expand Down
Loading