You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

114 lines
3.3 KiB

  1. // material-ui
  2. import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
  3. import {
  4. DataGrid,
  5. GridActionsCellItem,
  6. GridRowModes
  7. } from "@mui/x-data-grid";
  8. import * as React from 'react';
  9. import { useEffect } from "react";
  10. // import {useNavigate} from "react-router-dom";
  11. // import { useTheme } from '@mui/material/styles';
  12. import {
  13. Box,
  14. Stack
  15. } from '@mui/material';
  16. import {useIntl} from "react-intl";
  17. // ==============================|| EVENT TABLE ||============================== //
  18. export default function UploadFileTable({recordList, setRecordList,}) {
  19. const [rows, setRows] = React.useState(recordList);
  20. const [rowModesModel,setRowModesModel] = React.useState({});
  21. const intl = useIntl();
  22. // const theme = useTheme();
  23. // const navigate = useNavigate()
  24. useEffect(() => {
  25. setRows(recordList);
  26. // console.log(disableDelete);
  27. }, [recordList]);
  28. function NoRowsOverlay() {
  29. return (
  30. <Stack height="100%" alignItems="center" justifyContent="center">
  31. No File Record
  32. {/* <pre>(rows=&#123;[]&#125;)</pre> */}
  33. </Stack>
  34. );
  35. }
  36. const handleCancelClick = (id) => () => {
  37. setRowModesModel({
  38. ...rowModesModel,
  39. [id]: { mode: GridRowModes.View, ignoreModifications: true },
  40. });
  41. // console.log("Starting Delete")
  42. // const editedRow = rows.find((row) => row.id === id);
  43. // console.log(editedRow)
  44. // console.log(editedRow.isNew)
  45. setRecordList(rows.filter((row) => row.id !== id));
  46. setRows(rows.filter((row) => row.id !== id));
  47. }
  48. const columns = [
  49. {
  50. field: 'actions',
  51. type: 'actions',
  52. headerName: '',
  53. width: 30,
  54. cellClassName: 'actions',
  55. // hide:true,
  56. getActions: ({id}) => {
  57. return [
  58. <GridActionsCellItem
  59. key="OutSave"
  60. icon={<RemoveCircleOutlineIcon/>}
  61. label="delete"
  62. className="textPrimary"
  63. onClick={handleCancelClick(id)}
  64. color="error"
  65. />]
  66. },
  67. },
  68. {
  69. id: 'name',
  70. field: 'name',
  71. headerName: intl.formatMessage({id: 'fileName'}),
  72. flex: 1,
  73. },
  74. {
  75. id: 'size',
  76. field: 'size',
  77. headerName: intl.formatMessage({id: 'fileSize'}),
  78. valueGetter: (params) => {
  79. // console.log(params)
  80. return Math.ceil(params.value/1024)+" KB";
  81. },
  82. flex: 1,
  83. },
  84. ];
  85. return (
  86. <Box
  87. style={{ height: '200px', width: '75%' }}
  88. >
  89. <DataGrid
  90. rows={rows}
  91. columns={columns}
  92. editMode="row"
  93. sx={{border:1}}
  94. rowModesModel={rowModesModel}
  95. components={{ NoRowsOverlay, }}
  96. // hideFooterPagination={true}
  97. disablePagination
  98. disableSelectionOnClick
  99. disableColumnMenu
  100. disableColumnSelector
  101. hideFooter
  102. />
  103. </Box>
  104. );
  105. }