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.
 
 

118 lines
3.6 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. Stack, useMediaQuery
  14. } from '@mui/material';
  15. import {useTheme} from "@emotion/react";
  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 theme = useTheme();
  22. const isMdOrLg = useMediaQuery(theme.breakpoints.up('md'));
  23. const intl = useIntl();
  24. // const theme = useTheme();
  25. // const navigate = useNavigate()
  26. useEffect(() => {
  27. setRows(recordList);
  28. // console.log(disableDelete);
  29. }, [recordList]);
  30. function NoRowsOverlay() {
  31. return (
  32. <Stack height="100%" alignItems="center" justifyContent="center">
  33. No File Record
  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. setRecordList(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: intl.formatMessage({id: 'fileName'}),
  74. width: isMdOrLg ? 'auto' : 160,
  75. flex: isMdOrLg ? 1 : undefined,
  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. width: isMdOrLg ? 'auto' : 160,
  86. flex: isMdOrLg ? 1 : undefined,
  87. },
  88. ];
  89. return (
  90. <div
  91. style={{ height: '200px', width: '95%',overflowX: 'auto', }}
  92. >
  93. <DataGrid
  94. rows={rows}
  95. columns={columns}
  96. editMode="row"
  97. sx={{border:1}}
  98. rowModesModel={rowModesModel}
  99. components={{ NoRowsOverlay, }}
  100. // hideFooterPagination={true}
  101. disablePagination
  102. disableSelectionOnClick
  103. disableColumnMenu
  104. disableColumnSelector
  105. hideFooter
  106. />
  107. </div>
  108. );
  109. }