improve some option in reset table
This commit is contained in:
@@ -73,7 +73,6 @@ function HomeComponent() {
|
||||
"contains",
|
||||
"lessThan",
|
||||
"greaterThan",
|
||||
"between",
|
||||
],
|
||||
|
||||
},
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
import { Popper, Paper, List, ListItem, ListItemText, ClickAwayListener } from '@mui/material';
|
||||
import {ClickAwayListener, List, ListItem, ListItemText, Paper, Popper} from '@mui/material';
|
||||
|
||||
function FilterBox({anchorEl , open = false, handleClose = () => {} , columnFilterModeOptions , onSelectFilter , defaultFilter}) {
|
||||
const columnFilterModeOptionFa = {
|
||||
equals: "برابر",
|
||||
notEquals: "نابرابر",
|
||||
contains: "شامل",
|
||||
lessThan: "کوچکتر",
|
||||
greaterThan: "بزرگتر",
|
||||
}
|
||||
|
||||
function FilterBox({
|
||||
anchorEl, open = false, handleClose = () => {
|
||||
}, columnFilterModeOptions, onSelectFilter, defaultFilter
|
||||
}) {
|
||||
|
||||
const id = open ? 'simple-popper' : undefined;
|
||||
const handleSelectFilter = (filterFn) => {
|
||||
@@ -10,13 +21,14 @@ function FilterBox({anchorEl , open = false, handleClose = () => {} , columnFilt
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Popper id={id} open={open} anchorEl={anchorEl} placement="bottom" style={{ zIndex: 1301 }}>
|
||||
<Popper id={id} open={open} anchorEl={anchorEl} placement="bottom" style={{zIndex: 1301}}>
|
||||
<ClickAwayListener onClickAway={handleClose}>
|
||||
<Paper>
|
||||
<List>
|
||||
{columnFilterModeOptions.map((option, index) => (
|
||||
<ListItem key={index} onClick={() => handleSelectFilter(option)} selected={option === defaultFilter} sx={{ cursor: 'pointer' }}>
|
||||
<ListItemText primary={option} />
|
||||
<ListItem key={index} onClick={() => handleSelectFilter(option)}
|
||||
selected={option === defaultFilter} sx={{cursor: 'pointer'}}>
|
||||
<ListItemText primary={columnFilterModeOptionFa[option]}/>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
|
||||
@@ -19,7 +19,7 @@ const DataTable_TableHeadRow = ({
|
||||
const {virtualColumns, virtualPaddingLeft, virtualPaddingRight} =
|
||||
columnVirtualizer ?? {};
|
||||
|
||||
const backgroundColor = index % 2 === 0 ? '#2070af' : '#ff5c0f';
|
||||
const backgroundColor = index % 2 === 0 ? '#015688' : '#ff5c0f';
|
||||
|
||||
const tableRowProps = {
|
||||
...parseFromValuesOrFunc(muiTableHeadRowProps, {
|
||||
|
||||
28
src/core/components/DataTable/refactor/RefactorTable.jsx
Normal file
28
src/core/components/DataTable/refactor/RefactorTable.jsx
Normal file
@@ -0,0 +1,28 @@
|
||||
"use client"
|
||||
import {IconButton, Tooltip} from '@mui/material';
|
||||
import RestartAltIcon from '@mui/icons-material/RestartAlt';
|
||||
import useTableSetting from "@/lib/hooks/useTableSetting";
|
||||
import {useState} from "react";
|
||||
|
||||
function RefactorTable() {
|
||||
const {refactorAction} = useTableSetting();
|
||||
const [userId, setUserId] = useState(2);
|
||||
const [pageName, setPageName] = useState('loan');
|
||||
const [tableName, setTableName] = useState('loan_table');
|
||||
|
||||
const refactor = () => {
|
||||
refactorAction(userId, pageName, tableName);
|
||||
};
|
||||
|
||||
return (
|
||||
<Tooltip title="بازنشانی اطلاعات">
|
||||
<IconButton onClick={refactor} aria-label="refactor table">
|
||||
<RestartAltIcon/>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
export default RefactorTable;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import DataTable_LinearProgressBar from "./LinearProgressBar";
|
||||
import DataTable_TablePagination from "./TablePagination";
|
||||
import DataTable_ToolbarInternalButtons from "./ToolbarInternalButtons";
|
||||
import FilterColumn from "@/core/components/DataTable/filter/FilterColumn";
|
||||
import RefactorTable from "@/core/components/DataTable/refactor/RefactorTable";
|
||||
|
||||
const DataTable_TopToolbar = ({table, columns}) => {
|
||||
const {
|
||||
@@ -71,6 +72,7 @@ const DataTable_TopToolbar = ({table, columns}) => {
|
||||
justifyContent: 'flex-end',
|
||||
}}
|
||||
>
|
||||
<RefactorTable/>
|
||||
<FilterColumn columns={columns}/>
|
||||
<DataTable_ToolbarInternalButtons table={table}/>
|
||||
</Box>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client'
|
||||
import {createContext, useCallback, useEffect, useState} from "react";
|
||||
import {flattenArrayOfObjects} from "@/core/utils/flattenArrayOfObjects";
|
||||
|
||||
export const TableSettingContext = createContext();
|
||||
export const TableSettingProvider = ({children}) => {
|
||||
@@ -53,7 +52,23 @@ export const TableSettingProvider = ({children}) => {
|
||||
localStorage.setItem("_setting-app", JSON.stringify(updatedLocalStorage));
|
||||
setSettingStore(updatedLocalStorage);
|
||||
}
|
||||
|
||||
const refactorAction = (user_id, page_name, table_name) => {
|
||||
const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {};
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const refactorData = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
localStorage.setItem("_setting-app", JSON.stringify(refactorData));
|
||||
setSettingStore(refactorData);
|
||||
}
|
||||
const SummaryTextMessage = (values, columns) => {
|
||||
let SummaryText = "";
|
||||
let HideText = "";
|
||||
@@ -122,7 +137,7 @@ export const TableSettingProvider = ({children}) => {
|
||||
|
||||
return (
|
||||
<TableSettingContext.Provider
|
||||
value={{settingStore, hideAction, sortAction, filterAction}}>
|
||||
value={{settingStore, hideAction, sortAction, filterAction, refactorAction}}>
|
||||
{children}
|
||||
</TableSettingContext.Provider>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useContext } from "react";
|
||||
import { TableSettingContext } from "../contexts/tableSetting";
|
||||
import {useContext} from "react";
|
||||
import {TableSettingContext} from "../contexts/tableSetting";
|
||||
|
||||
const useTableSetting = () => {
|
||||
const { settingStore, hideAction, sortAction, filterAction } =
|
||||
useContext(TableSettingContext);
|
||||
return { settingStore, hideAction, sortAction, filterAction };
|
||||
const {settingStore, hideAction, sortAction, filterAction, refactorAction} =
|
||||
useContext(TableSettingContext);
|
||||
return {settingStore, hideAction, sortAction, filterAction, refactorAction};
|
||||
};
|
||||
|
||||
export default useTableSetting;
|
||||
|
||||
Reference in New Issue
Block a user