Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

168 rindas
5.0 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. import {CustomNoRowsOverlay} from "../../utils/CommonFunction";
  13. import {LIONER_BUTTON_THEME} from "../../themes/colorConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. // ==============================|| EVENT TABLE ||============================== //
  16. export default function UserTable({recordList}) {
  17. const [rows, setRows] = React.useState(recordList);
  18. const [rowModesModel] = React.useState({});
  19. const theme = useTheme();
  20. const navigate = useNavigate()
  21. const [paginationModel, setPaginationModel] = React.useState({
  22. page: 0,
  23. pageSize:10
  24. });
  25. useEffect(() => {
  26. setPaginationModel({page:0,pageSize:10});
  27. setRows(recordList);
  28. }, [recordList]);
  29. const handleEditClick = (id) => () => {
  30. navigate('/user/'+ id);
  31. };
  32. const columns = [
  33. {
  34. field: 'actions',
  35. type: 'actions',
  36. headerName: 'Actions',
  37. width: 100,
  38. cellClassName: 'actions',
  39. getActions: ({id}) => {
  40. return [
  41. <ThemeProvider key="OutSave" theme={LIONER_BUTTON_THEME}>
  42. <GridActionsCellItem
  43. key="OutSave"
  44. icon={
  45. <EditIcon sx={{fontSize:25}}/>
  46. }
  47. label="Edit"
  48. className="textPrimary"
  49. onClick={handleEditClick(id)}
  50. color="edit"
  51. />
  52. </ThemeProvider>]
  53. },
  54. },
  55. {
  56. id: 'username',
  57. field: 'username',
  58. headerName: 'User Name',
  59. flex: 0.8,
  60. },
  61. {
  62. id: 'name',
  63. field: 'fullname',
  64. headerName: 'Full Name',
  65. flex: 0.75,
  66. },
  67. {
  68. id: 'post',
  69. field: 'post',
  70. headerName: 'Post',
  71. flex: 0.5,
  72. },
  73. {
  74. id: 'email',
  75. field: 'email',
  76. headerName: 'Email',
  77. flex: 1.45,
  78. renderCell: (params) => {
  79. return (
  80. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  81. {params.value}
  82. </div>
  83. );
  84. }
  85. },
  86. {
  87. id: 'subDivision',
  88. field: 'subDivision',
  89. //type: 'date',
  90. //sortable: false,
  91. headerName: 'Sub-Division',
  92. flex: 1.45,
  93. renderCell: (params) => {
  94. return (
  95. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  96. {params.value}
  97. </div>
  98. );
  99. }
  100. },
  101. {
  102. id: 'lotusNotesUser',
  103. field: 'lotusNotesUser',
  104. type: 'bool',
  105. headerName: 'Lotus Notes',
  106. flex: 0.63,
  107. renderCell: (params) => {
  108. return (
  109. <Checkbox
  110. theme={theme}
  111. key="locked"
  112. checked={params.row.lotusNotesUser}
  113. color="primary"
  114. size="medium"
  115. //onChange={handleChange}
  116. />
  117. );
  118. },
  119. },
  120. {
  121. id: 'locked',
  122. field: 'locked',
  123. type: 'bool',
  124. headerName: 'Locked',
  125. flex: 0.5,
  126. renderCell: (params) => {
  127. return (
  128. <Checkbox
  129. theme={theme}
  130. key="locked"
  131. checked={params.row.locked}
  132. color="primary"
  133. size="medium"
  134. //onChange={handleChange}
  135. />
  136. );
  137. },
  138. },
  139. ];
  140. return (
  141. <div style={{/*height: '51vh',*/ width: '100%'}}>
  142. <DataGrid
  143. rows={rows}
  144. columns={columns}
  145. columnHeaderHeight={45}
  146. editMode="row"
  147. rowModesModel={rowModesModel}
  148. paginationModel={paginationModel}
  149. onPaginationModelChange={setPaginationModel}
  150. getRowHeight={() => 'auto'}
  151. slots={{
  152. noRowsOverlay: () => (
  153. CustomNoRowsOverlay()
  154. )
  155. }}
  156. pageSizeOptions={[10]}
  157. autoHeight
  158. />
  159. </div>
  160. );
  161. }