@aures/custom-react-table
Version:
dynamic table based on react table v7
676 lines • 47.8 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from 'react';
import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight';
import KeyboardArrowUp from '@mui/icons-material/KeyboardArrowUp';
import { Box, Grid, TableContainer, TableSortLabel, Tooltip, } from '@mui/material';
import { FixedSizeList } from 'react-window';
import { Card, CardBody, CardFooter, CardHeader } from 'reactstrap';
import { useColumnOrder, useExpanded, useFilters, useFlexLayout, useGlobalFilter, useGroupBy, usePagination, useResizeColumns, useRowSelect, useSortBy, useTable, } from 'react-table';
import { isMobile } from 'react-device-detect';
import { HeaderCheckbox, RawTable, RowCheckbox, TableBody, TableCell, TableHead, TableHeadCell, TableHeadRow, TableLabel, TableRow, useStyles, } from './TableStyle';
import { camelToWords, filterByReference, useDebounce, useLocalStorage, } from '../utils';
import { fuzzyTextFilter, numericTextFilter } from './filters';
import ChoiceIcon from './Choice';
import CollapsibleTable from './CollapsibleTable';
import { ColumnHidePageCustom } from './ColumnHidePageCustom';
import { CrossIcon } from '../components/assets/CrossIcon';
import DefaultGlobalFilter from './filters/defaultGlobalFilter';
import { FilterChipBar } from './FilterChipBar';
import { FilterIcon } from '../components/assets/FilterIcon';
import FilterModalMobile from './FilterModalMobile';
import { FilterPageCustom } from './FilterPageCustom';
import { ResizeHandle } from './ResizeHandle';
import { StyledH2 } from '../components/assets/StyledH2';
import SvgNoData from '../components/assets/SvgNoData';
import { TablePagination } from './TablePagination';
import { TableToolbar } from './TableToolbar';
import { TooltipCellRenderer } from './TooltipCell';
import DefaultColumnFilter from './DefaultColumnFilter';
import ControlledCheckbox from '../components/ControlledCheckbox';
import { useTranslation } from 'react-i18next';
import { calculateHeight } from '../utils/important';
function DefaultHeader({ column }) {
return _jsx(_Fragment, { children: column.id.startsWith('_') ? null : camelToWords(column.id) });
}
// yes this is recursive, but the depth never exceeds three so it seems safe enough
export const findFirstColumn = (columns) => columns[0].columns ? findFirstColumn(columns[0].columns) : columns[0];
const getStyles = (props, disableResizing = false, align = 'left') => [
props,
{
style: {
justifyContent: 'start',
alignItems: 'center',
display: 'flex',
},
},
];
const cellProps = (props, { cell }) => getStyles(props, cell.column && cell.column.disableResizing, cell.column && cell.column.align);
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/ban-types
function customFilter(rows, filterValues, id) {
return rows.filter((r) => {
const cellValue = r.values[id]; // Valeur de la cellule dans la colonne spécifiée par id
return filterValues.some((value) => cellValue.includes(value)); // Vérifie si la valeur de la cellule contient au moins une des valeurs de filterValues
});
}
// const filterTypes: any = {
// fuzzyText: fuzzyTextFilter,
// numeric: numericTextFilter,
// multiSelect: (rows: any, id: any, filterValues: any) => {
// if (filterValues.length === 0) return rows;
// return rows.filter((r: any) => filterValues.toString().includes(r.values[id]))
// // return rows.filter((r: any) => {
// // return r.values[id]?.includes(filterValues.toString())
// // });
// },
// };
// const filterTypes: any = {
// fuzzyText: fuzzyTextFilter,
// numeric: numericTextFilter,
// multiSelect: (rows: any, id: any, filterValues: any) => {
// if (filterValues.length === 0) return rows;
// return rows.filter((r: any) => {
// const cellValue: any = r.values[id]; // Using any type to handle different data types
// if (typeof cellValue === 'string') {
// return filterValues.some((value:any) => cellValue.includes(value));
// } else if (typeof cellValue === 'number') {
// // Convert number to string before checking for inclusion
// const stringValue = cellValue.toString();
// return filterValues.some((value:any) => stringValue.includes(value));
// }
// return false;
// });
// },
// };
// const filterTypes: any = {
// fuzzyText: fuzzyTextFilter,
// numeric: numericTextFilter,
// multiSelect: (rows: any, id: any, filterValues: any) => {
// if (filterValues.length === 0) return rows;
// return rows.filter((r: any) => {
// const cellValue: any = r.values[id];
// return filterValues.some((value: any) => cellValue?.toString()?.includes(value))
// });
// },
// };
// const filterTypes: any = {
// fuzzyText: fuzzyTextFilter,
// numeric: numericTextFilter,
// multiSelect: (rows: any, id: any, filterValues: any) => {
// if (filterValues.length === 0) return rows;
// return rows.filter((r: any) => {
// const cellValue: any = r.values[id];
// const matched = filterValues.some((value: any) => cellValue?.toString()?.includes(value));
// if (matched) {
// return true; // Si la ligne principale correspond au filtre, retourne true
// } else if (r.subRows) {
// // Si la ligne principale ne correspond pas, vérifie si des sous-lignes existent
// const subRowMatched = r.subRows.some((subRow: any) =>
// filterValues.some((value: any) => subRow.values[id]?.toString()?.includes(value))
// );
// return subRowMatched; // Retourne true si une sous-ligne correspond au filtre
// }
// return false; // Retourne false si ni la ligne principale ni les sous-lignes ne correspondent
// });
// },
// };
// 1032 const filterTypes: any = {
// fuzzyText: fuzzyTextFilter,
// numeric: numericTextFilter,
// multiSelect: (rows: any, id: any, filterValues: any) => {
// if (filterValues.length === 0) return rows;
// const filterRow = (row: any): boolean => {
// const cellValue: any = row.values[id];
// const matched = filterValues.some((value: any) => cellValue?.toString()?.includes(value));
// if (matched) {
// return true; // Si la ligne correspond au filtre, retourne true
// } else if (row.subRows) {
// // Si la ligne ne correspond pas, vérifie les sous-lignes récursivement
// return row.subRows.some((subRow: any) => filterRow(subRow));
// }
// return false; // Retourne false si ni la ligne ni les sous-lignes ne correspondent
// };
// // Filtrer les lignes principales en utilisant la fonction récursive
// return rows.filter((row: any) => filterRow(row));
// },
// };
// const filterTypes: any = {
// fuzzyText: fuzzyTextFilter,
// numeric: numericTextFilter,
// multiSelect: (rows: any, id: any, filterValues: any) => {
// if (filterValues.length === 0) return rows;
// const filterRow = (row: any): boolean => {
// const cellValue: any = row.values[id];
// let matched: boolean;
// if (id.includes("skills") || id.includes("hobby")) {
// // Use 'includes' for columns with ids containing 'skills' or 'hobby'
// matched = filterValues.some((value: any) => cellValue?.toString()?.includes(value));
// } else {
// // Use equality for other columns
// matched = filterValues.some((value: any) => cellValue === value);
// }
// if (matched) {
// return true; // If the row matches the filter, return true
// } else if (row.subRows) {
// // If the row does not match, recursively check sub-rows
// const subRowsMatched = row.subRows.some((subRow: any) => filterRow(subRow));
// if (subRowsMatched) {
// return true; // If at least one sub-row matches, return true
// }
// }
// // Return false if neither the row nor the sub-rows match
// return false;
// };
// // Filter rows using the filterRow function
// return rows.filter((row: any) => filterRow(row));
// },
// };
function getWidthByItem(items, targetItem) {
if ((items === null || items === void 0 ? void 0 : items.length) > 0) {
const foundItem = items.find((item) => item.item === targetItem);
return foundItem ? foundItem.width : '150px';
}
else {
return '150px';
}
}
const customSelectionHook = (hooks) => {
hooks.allColumns.push((columns) => [
// Let's make a column for selection
{
id: '_selector',
disableResizing: true,
disableGroupBy: true,
minWidth: 45,
width: 45,
maxWidth: 45,
Aggregated: undefined,
// The header can use the table's getToggleAllRowsSelectedProps method
// to render a checkbox
Header: (data) => {
const { row, dispatch, flatRows, isAllRowsSelected, state, toggleAllRowsSelected, allRows, selectedFlatRows, } = data;
return (_jsx(ControlledCheckbox, { data: data, state: state, isHeader: true, toggleAllRowsSelected: toggleAllRowsSelected, row: row, allRows: flatRows, instance: data, dispatchSelectedRows: dispatch, selectedFlatRows: selectedFlatRows, isAllRowsSelected: isAllRowsSelected, selectedRows: state.customSelectedRows, filters: state.filters, indeterminate: flatRows.length > 0 &&
flatRows.length === state.customSelectedRows.length
? false
: state.customSelectedRows.length > 0 }));
},
Cell: (data) => {
const { row, dispatch, flatRows, isAllRowsSelected, state, toggleAllRowsSelected, selectedFlatRows, allRows, } = data;
return (_jsx(ControlledCheckbox, { isHeader: false, row: row, instance: data, filters: state.filters, allRows: flatRows, dispatchSelectedRows: dispatch, selectedFlatRows: selectedFlatRows, isAllRowsSelected: isAllRowsSelected, selectedRows: state.customSelectedRows, indeterminate: false }));
},
},
...columns,
]);
};
const customSelectionHookWithMoveleft = (hooks) => {
hooks.allColumns.push((columns) => [
// Let's make a column for selection
{
id: '_selector',
disableResizing: true,
disableGroupBy: true,
minWidth: 45,
width: 45,
maxWidth: 45,
Aggregated: undefined,
// The header can use the table's getToggleAllRowsSelectedProps method
// to render a checkbox
Header: (data) => {
const { row, dispatch, flatRows, isAllRowsSelected, state, toggleAllRowsSelected, filteredRows, } = data;
// console.log({data,cc:10});
return (_jsx(ControlledCheckbox, { data: data, state: state, displayedRows: data.flatRows, isHeader: true, toggleAllRowsSelected: toggleAllRowsSelected, row: row, filteredRows: filteredRows, instance: data, filters: state.filters, allRows: flatRows, dispatchSelectedRows: dispatch, selectedFlatRows: flatRows, isAllRowsSelected: flatRows.length > 0 &&
flatRows.length === state.customSelectedRows.length, selectedRows: state.customSelectedRows, indeterminate: flatRows.length > 0 &&
flatRows.length === state.customSelectedRows.length
? false
: state.customSelectedRows.length > 0 }));
},
Cell: (data) => {
const { row, dispatch, flatRows, isAllRowsSelected, state, toggleAllRowsSelected, selectedFlatRows, } = data;
return (_jsx(ControlledCheckbox, { isHeader: false, row: row, instance: data, filters: state.filters, allRows: flatRows, dispatchSelectedRows: dispatch, selectedFlatRows: selectedFlatRows, isAllRowsSelected: isAllRowsSelected, selectedRows: state.customSelectedRows, indeterminate: false, movedLeft: true }));
},
},
...columns,
]);
};
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const headerProps = (
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
props, { column }) => getStyles(props, column && column.disableResizing, column && column.align);
export function Table(_a) {
var _b;
var { name, columns, canMovedCheckboxLeftOnExpand, onClick, canGroupBy, canSort, canSelect, setSelectedRows, customSelect, canResize, actionColumn, showGlobalFilter, showFilter, showColumnIcon, filterActive, setLocalFilterActive, customJsxDir, customJsxSideFilterButton, defaultHiddenColumns, defaultPaginationValues, toggleAllRowsExpanded, elevationTable, minHeight, maxHeight, tableFooter, isTableHasFooter, customClasses, customFilterJsx, allFiltersCustom, colsSetting } = _a, props = __rest(_a, ["name", "columns", "canMovedCheckboxLeftOnExpand", "onClick", "canGroupBy", "canSort", "canSelect", "setSelectedRows", "customSelect", "canResize", "actionColumn", "showGlobalFilter", "showFilter", "showColumnIcon", "filterActive", "setLocalFilterActive", "customJsxDir", "customJsxSideFilterButton", "defaultHiddenColumns", "defaultPaginationValues", "toggleAllRowsExpanded", "elevationTable", "minHeight", "maxHeight", "tableFooter", "isTableHasFooter", "customClasses", "customFilterJsx", "allFiltersCustom", "colsSetting"]);
const { t } = useTranslation();
const classes = useStyles();
const defaultColumn = {
//Filter: MultiSelectColumnFilter,
Filter: DefaultColumnFilter,
Cell: TooltipCellRenderer,
Header: DefaultHeader,
colsSetting: colsSetting || [],
// When using the useFlexLayout:
minWidth: 10,
//width: getWidthOfLongestString(columns.map((x: any) => x.id)), // width is used for both the flex-basis and flex-grow
maxWidth: 200, //getWidthOfLongestString(columns.map((x: any) => x.id)), // maxWidth is only used as a limit for resizing
};
if (name === undefined || name === null) {
name = 'mytable';
}
if (defaultHiddenColumns === undefined || defaultHiddenColumns === null) {
defaultHiddenColumns = ['78'];
}
const [initialState, setInitialState] = useLocalStorage(`tableState2:${name}`, {});
const customHooks = (hooks) => {
hooks.allColumns.push((columns) => [
...columns,
{
id: 'hidecolumns',
accessor: 'hidecolumns',
disableResizing: false,
disableGroupBy: true,
disableFilters: true,
disableSortBy: true,
canFilter: false,
minWidth: 60,
width: 60,
maxWidth: 100,
Header: () => (_jsxs("div", Object.assign({ className: "dropdown " }, { children: [_jsx("div", Object.assign({ id: "dropdownHideColomuns", "data-bs-toggle": "dropdown" }, { children: _jsx(ChoiceIcon, { height: 25, width: 25 }) })), _jsx("ul", Object.assign({ className: "dropdown-menu ", "aria-labelledby": "dropdownHideColomuns" }, { children: _jsx(ColumnHidePageCustom, { instance: instance }) }))] }))),
Cell(cell) {
const ActionColumnComponent = actionColumn;
return _jsx(ActionColumnComponent, { selectedRow: cell.row });
},
},
]);
};
function isUrl(str) {
// Regular expression for a simple URL check
const urlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/;
return urlRegex.test(str);
}
const hooks = [
useColumnOrder,
useFilters,
useGlobalFilter,
useGroupBy,
useSortBy,
useExpanded,
useFlexLayout,
usePagination,
useResizeColumns,
useRowSelect,
];
// eslint-disable-next-line
let localHooks = hooks;
const selectionHook = (hooks) => {
hooks.allColumns.push((columns) => [
// Let's make a column for selection
{
id: '_selector',
disableResizing: true,
disableGroupBy: true,
minWidth: 45,
width: 45,
maxWidth: 45,
Aggregated: undefined,
// align:"left",
// The header can use the table's getToggleAllRowsSelectedProps method
// to render a checkbox
Header: ({ getToggleAllRowsSelectedProps }) => (_jsx(HeaderCheckbox, Object.assign({}, getToggleAllRowsSelectedProps()))),
// The cell can use the individual row's getToggleRowSelectedProps method
// to the render a checkbox
Cell: ({ row }) => (_jsx(RowCheckbox, Object.assign({}, row.getToggleRowSelectedProps()))),
},
...columns,
]);
};
if (canSelect) {
if (customSelect) {
canMovedCheckboxLeftOnExpand !== undefined && canMovedCheckboxLeftOnExpand
? localHooks.push(customSelectionHookWithMoveleft)
: localHooks.push(customSelectionHook);
}
else {
localHooks.push(selectionHook);
}
}
if (actionColumn !== undefined) {
localHooks.push(customHooks);
}
const filterOptions = { filteredIds: [] };
let spCols = colsSetting
? (_b = colsSetting === null || colsSetting === void 0 ? void 0 : colsSetting.filter((setting) => typeof setting.filterContentSeparation === 'string')) === null || _b === void 0 ? void 0 : _b.map((setting) => setting.item)
: [];
const filterTypes = {
fuzzyText: fuzzyTextFilter,
numeric: numericTextFilter,
multiSelect: (rows, id, filterValues, columnsEquals) => {
if (filterValues.length === 0)
return rows;
const filterRow = (row) => {
const cellValue = row.values[id];
let matched;
// if (id.includes("skills") || id.includes("hobby")) {
if (spCols.some((keyword) => id.includes(keyword))) {
// Use 'includes' for columns with ids containing 'skills' or 'hobby'
matched = filterValues.some((value) => { var _a; return (_a = cellValue === null || cellValue === void 0 ? void 0 : cellValue.toString()) === null || _a === void 0 ? void 0 : _a.includes(value); });
}
else {
// Use equality for other columns
matched = filterValues.some((value) => cellValue === value);
}
if (matched) {
return true; // If the row matches the filter, return true
}
else if (row.subRows) {
// If the row does not match, recursively check sub-rows
const subRowsMatched = row.subRows.some((subRow) => filterRow(subRow));
if (subRowsMatched) {
return true; // If at least one sub-row matches, return true
}
}
// Return false if neither the row nor the sub-rows match
return false;
};
// Filter rows using the filterRow function
return rows.filter((row) => filterRow(row));
},
};
const instance = useTable(Object.assign(Object.assign({}, props), { columns,
filterTypes,
defaultColumn,
// styledRows: [],
getSubRows: (row) => row.subRows, globalFilter: (rows, columnIds, filterValue) => DefaultGlobalFilter(rows, columnIds, filterValue, filterOptions), initialState: Object.assign(Object.assign({}, initialState), { customSelectedRows: [], hiddenColumns: defaultHiddenColumns }), stateReducer: (newState, action, prevState) => {
switch (action.type) {
case 'customSelectRow':
return Object.assign(Object.assign({}, newState), { customSelectedRows: [
...newState.customSelectedRows,
action.payload,
] });
case 'customUnSelectRow':
return Object.assign(Object.assign({}, newState), { customSelectedRows: [
...newState.customSelectedRows.filter((elm) => elm.id !== action.payload),
] });
case 'unSelectedNestedRows':
const filteredRows = filterByReference(newState.customSelectedRows, action.payload, false);
return Object.assign(Object.assign({}, newState), { customSelectedRows: filteredRows });
case 'selectedNestedRows':
return Object.assign(Object.assign({}, newState), { customSelectedRows: [
...newState.customSelectedRows,
...action.payload,
] });
case 'customSelectAll':
return Object.assign(Object.assign({}, newState), { customSelectedRows: action.payload });
case 'customUnSelectAll':
return Object.assign(Object.assign({}, newState), { customSelectedRows: action.payload });
case 'customSelectAllV2':
let existingIds = new Set(newState.customSelectedRows.map((item) => item.id));
let mergedData = [
...newState.customSelectedRows,
...action.payload.filter((item) => !existingIds.has(item.id)),
];
return Object.assign(Object.assign({}, newState), { customSelectedRows: mergedData });
case 'customUnSelectAllV2':
const remainingSelections = newState.customSelectedRows.filter((selectedItem) => !action.payload.some((newItem) => newItem.id === selectedItem.id));
return Object.assign(Object.assign({}, newState), { customSelectedRows: remainingSelections });
default:
return newState;
}
} }), ...localHooks);
React.useEffect(() => {
const storedHiddenColumns = localStorage.getItem(name + '_hiddenColumns');
if (storedHiddenColumns) {
instance.setHiddenColumns(JSON.parse(storedHiddenColumns));
}
if (toggleAllRowsExpanded !== undefined && toggleAllRowsExpanded === true) {
instance.toggleAllRowsExpanded(true);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// Save column visibility settings to local storage whenever they change
React.useEffect(() => {
localStorage.setItem(name + '_hiddenColumns', JSON.stringify(instance.state.hiddenColumns));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [instance.state.hiddenColumns]);
React.useEffect(() => {
localStorage.setItem(name + '_colsSetting', JSON.stringify(colsSetting));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [instance]);
const { headerGroups, getTableBodyProps, page, prepareRow, state, selectedFlatRows, } = instance;
const debouncedState = useDebounce(state, 200);
const cellClickHandler = (cell) => () => {
onClick &&
!cell.column.isGrouped &&
!cell.row.isGrouped &&
cell.column.id !== '_selector' &&
onClick(cell.row);
};
function isDecimalOrFloat(input) {
// Regular expression to match a decimal or float (positive or negative)
const decimalOrFloatRegex = /^[-+]?[0-9]*\.?[0-9]+$/;
return decimalOrFloatRegex.test(input);
}
// let heightRow = (document.querySelector('.rowtrlist') as HTMLElement).offsetHeight;
React.useEffect(() => {
const { sortBy, filters, pageSize, columnResizing, selectedRowIds } = debouncedState;
const hiddenColumns = ['10'];
const json = JSON.parse(window.localStorage.getItem('tableState2:' + name) || '{}');
setInitialState({
sortBy,
filters: instance.state.filters,
pageSize: json.pageSize || pageSize,
columnResizing,
hiddenColumns,
selectedRowIds,
});
if (setSelectedRows !== undefined) {
if (instance.isAllRowsSelected) {
setSelectedRows(instance.flatRows.map((row) => (Object.assign(Object.assign({}, row.original), { depth: row.depth }))));
}
else if (customSelect !== undefined) {
setSelectedRows(state.customSelectedRows.map((row) => (Object.assign(Object.assign({}, row.original), { depth: row.depth }))));
}
else {
setSelectedRows(selectedFlatRows.map((row) => (Object.assign(Object.assign({}, row.original), { depth: row.depth }))));
}
}
// eslint-disable-next-line
}, [setInitialState, state.customSelectedRows, state.filters]);
// Example usages
if (maxHeight === undefined) {
maxHeight = '500px';
}
return (_jsx(React.Fragment, { children: isMobile === true ? (_jsxs(React.Fragment, { children: [_jsxs(CardHeader, Object.assign({ id: "TablePagination", style: { marginBottom: '2px' }, className: !showGlobalFilter && !showFilter && !showColumnIcon
? 'd-none'
: classes.cardHeaderCss }, { children: [_jsx(TableToolbar, Object.assign({ instance: instance }, {
showGlobalFilter,
showFilter,
showColumnIcon,
filterActive,
setLocalFilterActive,
customJsxDir,
customJsxSideFilterButton,
})), _jsx(FilterChipBar, { instance: instance, setLocalFilterActive: setLocalFilterActive, filterActive: filterActive })] })), _jsx(CardBody, Object.assign({ id: name, style: {
marginRight: '0',
marginLeft: '0',
padding: 0,
paddingTop: '4px ',
minHeight: '100vh',
fontFamily: 'Segoe UI, -apple-system, Helvetica Neue, Arial',
} }, { children: _jsx(CollapsibleTable, { props: instance, maxHeight: maxHeight, name: name, minHeight: minHeight }) })), _jsx(CardFooter, Object.assign({ id: "TablePagination", style: { backgroundColor: 'white', padding: '0' } }, { children: _jsx(TablePagination, { name: name, instance: instance, defaultPaginationValues: defaultPaginationValues ? defaultPaginationValues : [] }) })), filterActive ? (_jsx(FilterModalMobile, { instance: instance, setLocalFilterActive: setLocalFilterActive, filterActive: filterActive, tableName: name, customFilterJsx: customFilterJsx, allFiltersCustom: allFiltersCustom })) : null] })) : (_jsxs("div", Object.assign({ style: {
display: 'grid',
gridTemplateColumns: filterActive ? '2fr 1fr ' : 'auto',
gridColumnGap: '4px',
fontFamily: 'Segoe UI, -apple-system, Helvetica Neue, Arial',
} }, { children: [_jsxs(Card, Object.assign({ style: { border: '0px' } }, { children: [_jsxs(CardHeader, Object.assign({ id: "TableToolbar", className: !showGlobalFilter && !showFilter && !showColumnIcon
? 'd-none'
: classes.cardHeaderCss }, { children: [_jsx(TableToolbar, Object.assign({ instance: instance }, {
showGlobalFilter,
showFilter,
showColumnIcon,
filterActive,
setLocalFilterActive,
customJsxDir,
customJsxSideFilterButton,
})), _jsx(FilterChipBar, { instance: instance, setLocalFilterActive: setLocalFilterActive, filterActive: filterActive })] })), _jsx(CardBody, Object.assign({ id: name, style: {
marginRight: '0',
marginLeft: '0',
padding: 0,
paddingTop: '4px !important ',
border: '1px solid rgba(0,0,0,.125)',
} }, { children: _jsx(Grid, Object.assign({ container: true, id: "tablecontainer", direction: 'row', sx: { display: 'grid' } }, { children: _jsx(TableContainer, Object.assign({ sx: {
paddingRight: '0!important',
paddingLeft: '0!important',
overflowX: 'auto',
overflowY: page.length === 0 || true ? 'hidden' : 'auto',
display: 'block',
width: '100%',
WebkitOverflowScrolling: 'touch',
MsOverflowStyle: '-ms-autohiding-scrollbar',
// flex: '1 1 auto',
paddingBottom: '0px !important',
marginTop: '0 !important',
paddingTop: '0 !important',
maxHeight: maxHeight === 0 ||
maxHeight === '' ||
maxHeight === undefined
? '630px'
: maxHeight,
minHeight: minHeight === 0 ||
minHeight === '' ||
minHeight === undefined
? '580px'
: minHeight,
}, className: "table-responsive" }, { children: _jsxs(RawTable, { children: [_jsx(TableHead, Object.assign({ className: 'header' + name }, { children: headerGroups.map((headerGroup) => {
const _a = headerGroup.getHeaderGroupProps(), { key: headerGroupKey, title: headerGroupTitle, role: headerGroupRole } = _a, getHeaderGroupProps = __rest(_a, ["key", "title", "role"]);
return (_jsx(TableHeadRow, Object.assign({}, getHeaderGroupProps, { children: headerGroup.headers.map((column) => {
const style = {
textAlign: column.align
? column.align
: 'center ',
};
const _a = column.getHeaderProps(headerProps), { key: headerKey, role: headerRole } = _a, getHeaderProps = __rest(_a, ["key", "role"]);
const _b = column.getGroupByToggleProps(), { title: groupTitle = '' } = _b, columnGroupByProps = __rest(_b, ["title"]);
const _c = column.getSortByToggleProps({
title: t('Sort'),
}), { title: sortTitle = '' } = _c, columnSortByProps = __rest(_c, ["title"]);
let styleEl = getHeaderProps.style;
// styleEl.background ="red"
styleEl.width = getWidthByItem(colsSetting, column.Header);
return (_jsxs(TableHeadCell, Object.assign({}, getHeaderProps, { style: styleEl }, { children: [canGroupBy
? column.canGroupBy && (_jsx(Tooltip, Object.assign({ title: groupTitle }, { children: _jsx(TableSortLabel, Object.assign({ active: true,
// direction={column.isGrouped ? 'desc' : 'asc'}
IconComponent: KeyboardArrowRight }, columnGroupByProps, { className: classes.headerIcon })) })))
: null, column.canSort && canSort ? (_jsx(Tooltip, Object.assign({ title: sortTitle }, { children: _jsx(TableSortLabel, Object.assign({ active: column.isSorted, direction: column.isSortedDesc ? 'desc' : 'asc' }, columnSortByProps, { className: `${classes.tableSortLabel} ${(customClasses === null || customClasses === void 0 ? void 0 : customClasses.thead)
? customClasses === null || customClasses === void 0 ? void 0 : customClasses.thead
: ''}`, style: { flexDirection: 'row-reverse' } }, { children: column.render('Header') })) }))) : (_jsx(TableLabel, Object.assign({ style: style }, { children: column.render('Header') }))), canResize
? column.canResize && (_jsx(ResizeHandle, { column: column }))
: null] }), headerKey));
}) }), headerGroupKey));
}) })), page.length !== 0 && (_jsx(TableBody, Object.assign({}, getTableBodyProps(), { className: page.length === 0 ? classes.SvgNoDataCss : '', style: { minHeight } }, { children: _jsx(FixedSizeList
// height={790} // Adjust the height as needed
, Object.assign({
// height={790} // Adjust the height as needed
height: Number(calculateHeight(maxHeight, 'header' + name, name)), className: "tableContent", itemCount: page.length, itemSize: 50, width: '100%', style: {
overflow: 'hidden',
overflowY: 'auto',
} }, { children: ({ index, style }) => {
const row = page[index];
prepareRow(row);
return (_jsx(TableRow, Object.assign({}, row.getRowProps(), { style: Object.assign(Object.assign({}, style), { display: 'flex', flexDirection: 'row' }), className: `tr ${row.isSelected ? 'selected' : ''}` }, { children: row.cells.map((cell) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
const _m = cell.getCellProps(cellProps), { key: cellKey, role: cellRole } = _m, getCellProps = __rest(_m, ["key", "role"]);
const cellColumnId = cell.column.id;
if (cellColumnId.includes('.')) {
// console.log(cellColumnId,cell.row.original[`${cellColumnId}`]);
const cellRendered = cell === null || cell === void 0 ? void 0 : cell.render('Cell');
if (React.isValidElement(cellRendered)) {
// Assurez-vous qu'il s'agit d'un élément React valide
const children = React.Children.toArray(cellRendered.props.children);
children.map((header) => {
if (header.id === cellColumnId) {
header.accessor = (row) => row[cellColumnId];
}
return header;
});
}
}
let styleEl = getCellProps.style;
// styleEl.background ="red"
styleEl.width = getWidthByItem(colsSetting, cellColumnId);
let alignItems = { align: '' };
alignItems.align =
((_a = colsSetting === null || colsSetting === void 0 ? void 0 : colsSetting.find((x) => x.item === cellColumnId)) === null || _a === void 0 ? void 0 : _a.align) || '';
return (_jsx(TableCell, Object.assign({}, getCellProps, { style: styleEl, onClick: cellClickHandler(cell) }, { children: _jsx("span", Object.assign({ style: typeof cell.value === 'string'
? {
overflow: 'hidden',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
width: '100%',
display: 'inline !important',
}
: {},
// className={`${cellKey.toLowerCase().includes('action') && 'text-left '} ${
// cellKey.toLowerCase().includes('hidecolumns') && 'text-left '
// } `}
className: `w-100 ${(alignItems === null || alignItems === void 0 ? void 0 : alignItems.align) === 'center'
? 'text-center'
: (alignItems === null || alignItems === void 0 ? void 0 : alignItems.align) === 'left'
? 'text-left'
: (alignItems === null || alignItems === void 0 ? void 0 : alignItems.align) === 'right'
? 'text-right'
: isDecimalOrFloat((_b = cell === null || cell === void 0 ? void 0 : cell.row) === null || _b === void 0 ? void 0 : _b.original[`${(_c = cell === null || cell === void 0 ? void 0 : cell.column) === null || _c === void 0 ? void 0 : _c.id}`]) &&
['action'].indexOf((_e = (_d = cell.column) === null || _d === void 0 ? void 0 : _d.id) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === -1
? 'text-right '
: 'text-left'} ` }, { children: cell.isGrouped ? (_jsxs(_Fragment, { children: [_jsx(TableSortLabel, Object.assign({ classes: {
iconDirectionAsc: classes.iconDirectionAsc,
iconDirectionDesc: classes.iconDirectionDesc,
}, active: true, direction: row.isExpanded ? 'desc' : 'asc', IconComponent: KeyboardArrowUp }, row.getToggleRowExpandedProps(), { className: classes.cellIcon })), ' ', cell.render('Cell', {
editable: false,
}), ' ', "(", row.subRows.length, ")"] })) : cell.isAggregated ? (((_f = cell === null || cell === void 0 ? void 0 : cell.column) === null || _f === void 0 ? void 0 : _f.id.includes('.')) ? ((_g = cell === null || cell === void 0 ? void 0 : cell.row) === null || _g === void 0 ? void 0 : _g.original[`${(_h = cell === null || cell === void 0 ? void 0 : cell.column) === null || _h === void 0 ? void 0 : _h.id}`]) : (cell.render('Aggregated'))) : cell.isPlaceholder ? null : ((_j = cell === null || cell === void 0 ? void 0 : cell.column) === null || _j === void 0 ? void 0 : _j.id.includes('.')) ? ((_k = cell === null || cell === void 0 ? void 0 : cell.row) === null || _k === void 0 ? void 0 : _k.original[`${(_l = cell === null || cell === void 0 ? void 0 : cell.column) === null || _l === void 0 ? void 0 : _l.id}`]) : (cell.render('Cell')) })) }), cellKey));
}) })));
} })) }))), page.length === 0 && (_jsx(TableBody, Object.assign({}, getTableBodyProps(), { className: page.length === 0 ? classes.SvgNoDataCss : '', style: { minHeight } }, { children: _jsx("div", Object.assign({ className: page.length === 0 ? classes.SvgNoDataCss : 'd-none', style: {
position: 'relative',
paddingTop: '70px',
paddingBottom: '70px',
} }, { children: _jsx(SvgNoData, {}) })) }))), isTableHasFooter && tableFooter && (_jsx("tfoot", Object.assign({ className: name + '_table_footer', style: { position: 'sticky', bottom: '0px' } }, { children: tableFooter })))] }) })) })) })), _jsx(CardFooter, Object.assign({ id: "TablePagination", style: {
backgroundColor: 'white',
border: '1px solid rgba(0,0,0,.125)',
borderTop: '0px',
borderRadius: '0px 0px 12px 12px',
} }, { children: _jsx(TablePagination, { name: name, instance: instance, defaultPaginationValues: defaultPaginationValues ? defaultPaginationValues : [] }) }))] })), filterActive ? (_jsxs(Card, Object.assign({ style: { border: '0px' } }, { children: [_jsxs(CardHeader, Object.assign({ style: {
display: 'flex',
alignItems: 'center',
// marginBottom: '2px',
maxHeight: '64px !important',
justifyContent: 'space-between',
}, className: `${classes.FiltersCss} ${classes.cardHeaderCss}` }, { children: [_jsxs(Box, Object.assign({ sx: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
paddingLeft: '10px',
color: 'red',
} }, { children: [_jsx(FilterIcon, { className: classes.tableFilterAltOutlinedIcon, style: { flexDirection: 'row-reverse' } }), _jsx(StyledH2, Object.assign({ style: { marginBottom: 0 } }, { children: t('Filter(s)') }))] })), _jsx(CrossIcon, { style: { cursor: 'pointer' }, height: 11, width: 25, onClick: () => {
setLocalFilterActive(false);
} })] })), _jsx(CardBody, Object.assign({ id: "filterbody", style: {
marginRight: '0',
marginLeft: '0',
padding: 0,
paddingTop: '4px !important ',
border: '1px solid rgba(0,0,0,.125)',
backgroundColor: 'white',
borderTop: '1px solid rgba(0,0,0,.125)',
borderRadius: '0px 0px 12px 12px ',
// borderRadius: '20px 20px 12px 12px !important;',
} }, { children: _jsx(FilterPageCustom, { instance: instance, setLocalFilterActive: setLocalFilterActive, filterActive: filterActive, tableName: name, customFilterJsx: customFilterJsx, allFiltersCustom: allFiltersCustom }) }))] }))) : null] }))) }));
}
export default Table;
//# sourceMappingURL=Table.js.map