您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

119 行
3.5 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. Typography
  16. } from '@mui/material';
  17. import {FormattedMessage} from "react-intl";
  18. // ==============================|| EVENT TABLE ||============================== //
  19. export default function UploadFileTable({ recordList, setUpdateRows, }) {
  20. const [rows, setRows] = React.useState(recordList);
  21. const [rowModesModel, setRowModesModel] = React.useState({});
  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. <Typography variant="h6">
  32. <FormattedMessage id="noFile"/>
  33. </Typography>
  34. {/* <pre>(rows=&#123;[]&#125;)</pre> */}
  35. </Stack>
  36. );
  37. }
  38. const handleCancelClick = (id) => () => {
  39. setRowModesModel({
  40. ...rowModesModel,
  41. [id]: { mode: GridRowModes.View, ignoreModifications: true },
  42. });
  43. console.log("Starting Delete")
  44. const editedRow = rows.find((row) => row.id === id);
  45. console.log(editedRow)
  46. console.log(editedRow.isNew)
  47. setUpdateRows(rows.filter((row) => row.id !== id));
  48. setRows(rows.filter((row) => row.id !== id));
  49. }
  50. const columns = [
  51. {
  52. field: 'actions',
  53. type: 'actions',
  54. headerName: '',
  55. width: 30,
  56. cellClassName: 'actions',
  57. // hide:true,
  58. getActions: ({ id }) => {
  59. return [
  60. <GridActionsCellItem
  61. key="OutSave"
  62. icon={<RemoveCircleOutlineIcon />}
  63. label="delete"
  64. className="textPrimary"
  65. onClick={handleCancelClick(id)}
  66. color="error"
  67. />]
  68. },
  69. },
  70. {
  71. id: 'name',
  72. field: 'name',
  73. headerName: <Typography variant="h6">
  74. <FormattedMessage id="fileName"/>
  75. </Typography>,
  76. flex: 4,
  77. },
  78. {
  79. id: 'size',
  80. field: 'size',
  81. headerName: <Typography variant="h6">
  82. <FormattedMessage id="fileSize"/>
  83. </Typography>,
  84. valueGetter: (params) => {
  85. // console.log(params)
  86. return Math.ceil(params.value / 1024) + " KB";
  87. },
  88. flex: 2,
  89. },
  90. ];
  91. return (
  92. <Box style={{ height: '200px', width: '100%' }}>
  93. <DataGrid
  94. rows={rows}
  95. columns={columns}
  96. editMode="row"
  97. sx={{ border: 1 }}
  98. rowModesModel={rowModesModel}
  99. disablePagination
  100. components={{ NoRowsOverlay, }}
  101. // hideFooterPagination={true}
  102. disableSelectionOnClick
  103. disableColumnMenu
  104. disableColumnSelector
  105. hideFooter
  106. getRowHeight={()=>"auto"}
  107. />
  108. </Box>
  109. );
  110. }