Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

110 строки
3.2 KiB

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