fix: selected row 상태 표시 추가

main
minuk926 3 years ago
parent db1752d397
commit 86ade7e4ee

@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord'; import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord';
import { Typography } from '@mui/material'; import { Typography } from '@mui/material';
const CustomPagination = ({ totalCount }) => { const CustomPagination = ({ totalCount, numSelected }) => {
const apiRef = useGridApiContext(); const apiRef = useGridApiContext();
const page = useGridSelector(apiRef, gridPageSelector); const page = useGridSelector(apiRef, gridPageSelector);
const pageCount = useGridSelector(apiRef, gridPageCountSelector); const pageCount = useGridSelector(apiRef, gridPageCountSelector);
@ -30,6 +30,11 @@ const CustomPagination = ({ totalCount }) => {
}} }}
/> />
)} )}
{numSelected > 0 && (
<Typography color="inherit" variant="subtitle1">
{numSelected} 선택
</Typography>
)}
{pageCount > 1 && ( {pageCount > 1 && (
<FiberManualRecordIcon <FiberManualRecordIcon
fontSize="small" fontSize="small"
@ -50,7 +55,7 @@ const CustomPagination = ({ totalCount }) => {
}; };
CustomPagination.propTypes = { CustomPagination.propTypes = {
totalCount: PropTypes.number.isRequired totalCount: PropTypes.number.isRequired,
// pageSize: PropTypes.number.isRequired numSelected: PropTypes.number
}; };
export default CustomPagination; export default CustomPagination;

@ -9,6 +9,8 @@ import Box from '@mui/material/Box';
import { useTheme } from '@mui/styles'; import { useTheme } from '@mui/styles';
import dataGridKoKR from './defaultDataGridLocale'; import dataGridKoKR from './defaultDataGridLocale';
import CustomPagination from './CustomPagination'; import CustomPagination from './CustomPagination';
import { IconButton, Toolbar, Tooltip, Typography } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete';
// TODO : grid style // TODO : grid style
/* /*
@ -91,9 +93,27 @@ const styles = (theme) => ({
}); });
*/ */
const EnhancedTableToolbar = ({ children }) => (
<Toolbar
sx={{
p: 0,
pl: 1,
pr: 1
}}
>
{children}
</Toolbar>
);
EnhancedTableToolbar.propTypes = {
children: PropTypes.node
};
// project imports // project imports
const MuiDataGrid = ({ const MuiDataGrid = ({
// apiRef = () => {}, // apiRef = () => {},
isToolbar = false,
children = <div />,
isCheckbox = false, isCheckbox = false,
// isDisableSelection = true, // isDisableSelection = true,
columns, columns,
@ -107,6 +127,7 @@ const MuiDataGrid = ({
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
const { pageSize } = rowsState; const { pageSize } = rowsState;
const numSelected = selectionModel.length;
const getRowSpacing = useCallback( const getRowSpacing = useCallback(
(params) => ({ (params) => ({
@ -141,6 +162,7 @@ const MuiDataGrid = ({
} }
}} }}
> >
{isToolbar && <EnhancedTableToolbar>{children}</EnhancedTableToolbar>}
<DataGrid <DataGrid
// apiRef={apiRef} // apiRef={apiRef}
// showCellRightBorder // showCellRightBorder
@ -166,7 +188,7 @@ const MuiDataGrid = ({
Footer: CustomPagination Footer: CustomPagination
}} }}
componentsProps={{ componentsProps={{
footer: { totalCount, pageSize } footer: { totalCount, pageSize, numSelected }
}} }}
hideFooterRowCount={false} hideFooterRowCount={false}
hideFooterSelectedRowCount={false} hideFooterSelectedRowCount={false}
@ -201,6 +223,8 @@ const MuiDataGrid = ({
MuiDataGrid.propTypes = { MuiDataGrid.propTypes = {
// apiRef: PropTypes.func, // apiRef: PropTypes.func,
isToolbar: PropTypes.bool.isRequired,
children: PropTypes.node,
isCheckbox: PropTypes.bool, isCheckbox: PropTypes.bool,
// isDisableSelection: PropTypes.bool, // isDisableSelection: PropTypes.bool,
columns: PropTypes.array.isRequired, columns: PropTypes.array.isRequired,

Loading…
Cancel
Save