improve some option in reset table
This commit is contained in:
@@ -73,7 +73,6 @@ function HomeComponent() {
|
|||||||
"contains",
|
"contains",
|
||||||
"lessThan",
|
"lessThan",
|
||||||
"greaterThan",
|
"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 id = open ? 'simple-popper' : undefined;
|
||||||
const handleSelectFilter = (filterFn) => {
|
const handleSelectFilter = (filterFn) => {
|
||||||
@@ -10,13 +21,14 @@ function FilterBox({anchorEl , open = false, handleClose = () => {} , columnFilt
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<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}>
|
<ClickAwayListener onClickAway={handleClose}>
|
||||||
<Paper>
|
<Paper>
|
||||||
<List>
|
<List>
|
||||||
{columnFilterModeOptions.map((option, index) => (
|
{columnFilterModeOptions.map((option, index) => (
|
||||||
<ListItem key={index} onClick={() => handleSelectFilter(option)} selected={option === defaultFilter} sx={{ cursor: 'pointer' }}>
|
<ListItem key={index} onClick={() => handleSelectFilter(option)}
|
||||||
<ListItemText primary={option} />
|
selected={option === defaultFilter} sx={{cursor: 'pointer'}}>
|
||||||
|
<ListItemText primary={columnFilterModeOptionFa[option]}/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const DataTable_TableHeadRow = ({
|
|||||||
const {virtualColumns, virtualPaddingLeft, virtualPaddingRight} =
|
const {virtualColumns, virtualPaddingLeft, virtualPaddingRight} =
|
||||||
columnVirtualizer ?? {};
|
columnVirtualizer ?? {};
|
||||||
|
|
||||||
const backgroundColor = index % 2 === 0 ? '#2070af' : '#ff5c0f';
|
const backgroundColor = index % 2 === 0 ? '#015688' : '#ff5c0f';
|
||||||
|
|
||||||
const tableRowProps = {
|
const tableRowProps = {
|
||||||
...parseFromValuesOrFunc(muiTableHeadRowProps, {
|
...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_TablePagination from "./TablePagination";
|
||||||
import DataTable_ToolbarInternalButtons from "./ToolbarInternalButtons";
|
import DataTable_ToolbarInternalButtons from "./ToolbarInternalButtons";
|
||||||
import FilterColumn from "@/core/components/DataTable/filter/FilterColumn";
|
import FilterColumn from "@/core/components/DataTable/filter/FilterColumn";
|
||||||
|
import RefactorTable from "@/core/components/DataTable/refactor/RefactorTable";
|
||||||
|
|
||||||
const DataTable_TopToolbar = ({table, columns}) => {
|
const DataTable_TopToolbar = ({table, columns}) => {
|
||||||
const {
|
const {
|
||||||
@@ -71,6 +72,7 @@ const DataTable_TopToolbar = ({table, columns}) => {
|
|||||||
justifyContent: 'flex-end',
|
justifyContent: 'flex-end',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<RefactorTable/>
|
||||||
<FilterColumn columns={columns}/>
|
<FilterColumn columns={columns}/>
|
||||||
<DataTable_ToolbarInternalButtons table={table}/>
|
<DataTable_ToolbarInternalButtons table={table}/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import {createContext, useCallback, useEffect, useState} from "react";
|
import {createContext, useCallback, useEffect, useState} from "react";
|
||||||
import {flattenArrayOfObjects} from "@/core/utils/flattenArrayOfObjects";
|
|
||||||
|
|
||||||
export const TableSettingContext = createContext();
|
export const TableSettingContext = createContext();
|
||||||
export const TableSettingProvider = ({children}) => {
|
export const TableSettingProvider = ({children}) => {
|
||||||
@@ -53,7 +52,23 @@ export const TableSettingProvider = ({children}) => {
|
|||||||
localStorage.setItem("_setting-app", JSON.stringify(updatedLocalStorage));
|
localStorage.setItem("_setting-app", JSON.stringify(updatedLocalStorage));
|
||||||
setSettingStore(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) => {
|
const SummaryTextMessage = (values, columns) => {
|
||||||
let SummaryText = "";
|
let SummaryText = "";
|
||||||
let HideText = "";
|
let HideText = "";
|
||||||
@@ -122,7 +137,7 @@ export const TableSettingProvider = ({children}) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<TableSettingContext.Provider
|
<TableSettingContext.Provider
|
||||||
value={{settingStore, hideAction, sortAction, filterAction}}>
|
value={{settingStore, hideAction, sortAction, filterAction, refactorAction}}>
|
||||||
{children}
|
{children}
|
||||||
</TableSettingContext.Provider>
|
</TableSettingContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useContext } from "react";
|
import {useContext} from "react";
|
||||||
import { TableSettingContext } from "../contexts/tableSetting";
|
import {TableSettingContext} from "../contexts/tableSetting";
|
||||||
|
|
||||||
const useTableSetting = () => {
|
const useTableSetting = () => {
|
||||||
const { settingStore, hideAction, sortAction, filterAction } =
|
const {settingStore, hideAction, sortAction, filterAction, refactorAction} =
|
||||||
useContext(TableSettingContext);
|
useContext(TableSettingContext);
|
||||||
return { settingStore, hideAction, sortAction, filterAction };
|
return {settingStore, hideAction, sortAction, filterAction, refactorAction};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useTableSetting;
|
export default useTableSetting;
|
||||||
|
|||||||
Reference in New Issue
Block a user