Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

119 wiersze
3.1 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. DataGrid,
  5. GridActionsCellItem,
  6. } from "@mui/x-data-grid";
  7. import EditIcon from '@mui/icons-material/Edit';
  8. import {useEffect} from "react";
  9. import {useNavigate} from "react-router-dom";
  10. import { useTheme } from '@mui/material/styles';
  11. import Checkbox from '@mui/material/Checkbox';
  12. // ==============================|| EVENT TABLE ||============================== //
  13. export default function UserTable({recordList}) {
  14. const [rows, setRows] = React.useState(recordList);
  15. const [rowModesModel] = React.useState({});
  16. const theme = useTheme();
  17. const navigate = useNavigate()
  18. useEffect(() => {
  19. setRows(recordList);
  20. }, [recordList]);
  21. const handleEditClick = (id) => () => {
  22. navigate('/user/'+ id);
  23. };
  24. const columns = [
  25. {
  26. field: 'actions',
  27. type: 'actions',
  28. headerName: 'Actions',
  29. width: 100,
  30. cellClassName: 'actions',
  31. getActions: ({id}) => {
  32. return [
  33. <GridActionsCellItem
  34. key="OutSave"
  35. icon={<EditIcon/>}
  36. label="Edit"
  37. className="textPrimary"
  38. onClick={handleEditClick(id)}
  39. color="primary"
  40. />]
  41. },
  42. },
  43. {
  44. id: 'username',
  45. field: 'username',
  46. headerName: 'User Name',
  47. flex: 1,
  48. },
  49. {
  50. id: 'name',
  51. field: 'name',
  52. headerName: 'Full Name',
  53. flex: 1,
  54. },
  55. {
  56. id: 'post',
  57. field: 'post',
  58. headerName: 'Post',
  59. flex: 1,
  60. },
  61. {
  62. id: 'email',
  63. field: 'email',
  64. headerName: 'Email',
  65. flex: 1,
  66. },
  67. {
  68. id: 'subDivisionId',
  69. field: 'subDivisionId',
  70. //type: 'date',
  71. //sortable: false,
  72. headerName: 'Sub-Division',
  73. flex: 1,
  74. },
  75. {
  76. id: 'locked',
  77. field: 'locked',
  78. type: 'bool',
  79. headerName: 'Locked',
  80. flex: 1,
  81. renderCell: (params) => {
  82. return (
  83. <Checkbox
  84. theme={theme}
  85. key="locked"
  86. checked={params.row.locked}
  87. color="primary"
  88. size="small"
  89. //onChange={handleChange}
  90. />
  91. );
  92. },
  93. },
  94. ];
  95. return (
  96. <div style={{height: 400, width: '100%'}}>
  97. <DataGrid
  98. rows={rows}
  99. columns={columns}
  100. editMode="row"
  101. rowModesModel={rowModesModel}
  102. initialState={{
  103. pagination: {
  104. paginationModel: {page: 0, pageSize: 5},
  105. },
  106. }}
  107. pageSizeOptions={[5, 10]}
  108. autoHeight
  109. />
  110. </div>
  111. );
  112. }