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

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