Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

221 rader
7.4 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 PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
  9. import {useContext, useEffect} from "react";
  10. import {useNavigate} from "react-router-dom";
  11. import {CustomNoRowsOverlay, dateComparator, getDateString} from "../../../utils/CommonFunction";
  12. import AbilityContext from "../../../components/AbilityProvider";
  13. import {LIONER_BUTTON_THEME} from "../../../themes/colorConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. // ==============================|| PDF TABLE ||============================== //
  16. export default function PdfTable({recordList}) {
  17. const [rows, setRows] = React.useState(recordList);
  18. const [rowModesModel] = React.useState({});
  19. const navigate = useNavigate()
  20. const ability = useContext(AbilityContext);
  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(`/pdf/maintain/${id}`);
  31. };
  32. const columns = [
  33. {
  34. field: 'actions',
  35. type: 'actions',
  36. headerName: 'Actions',
  37. // flex: 0.5,
  38. width: 100,
  39. cellClassName: 'actions',
  40. getActions: ({id}) => {
  41. return [
  42. <ThemeProvider key="OutSave" theme={LIONER_BUTTON_THEME}>
  43. <GridActionsCellItem
  44. icon={<EditIcon sx={{fontSize: 25}}/>}
  45. label="Edit"
  46. className="textPrimary"
  47. onClick={handleEditClick(id)}
  48. color="edit"
  49. // disabled={'true'}
  50. // disabled={!ability.can('VIEW','DASHBOARD')}
  51. />
  52. </ThemeProvider>
  53. ]
  54. },
  55. },
  56. // {
  57. // id: 'title',
  58. // field: 'title',
  59. // headerName: 'Title',
  60. // // sortComparator: dateComparator,
  61. // flex: 0.75,
  62. // renderCell: (params) => (
  63. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  64. // {params.value}
  65. // </div>
  66. // // <div>
  67. // // {getDateString(params.row.pdfFrom,false)}
  68. // // </div>
  69. // ),
  70. // },
  71. {
  72. id: 'templateId',
  73. field: 'templateId',
  74. headerName: 'Form Name',
  75. flex: 2,
  76. renderCell: (params) => {
  77. return (
  78. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  79. {params.value}
  80. </div>
  81. );
  82. }
  83. },
  84. {
  85. id: 'createDate',
  86. field: 'createDate',
  87. headerName: 'Create Date',
  88. flex: 1,
  89. sortComparator: dateComparator,
  90. renderCell: (params) => (
  91. <div>
  92. {getDateString(params.row.created, 'dd/MM/yyyy')}
  93. </div>
  94. ),
  95. },
  96. {
  97. id: 'modified',
  98. field: 'modified',
  99. headerName: 'Modified Date',
  100. flex: 1,
  101. sortComparator: dateComparator,
  102. renderCell: (params) => (
  103. <div>
  104. {getDateString(params.row.modified, 'dd/MM/yyyy')}
  105. </div>
  106. ),
  107. },
  108. // {
  109. // id: 'lastname',
  110. // field: 'lastname',
  111. // headerName: 'Last Name',
  112. // flex: 1.5,
  113. // sortComparator: dateComparator,
  114. // renderCell: (params) => (
  115. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  116. // {params.value}
  117. // </div>
  118. // // <div>
  119. // // {getDateString(params.row.startDate,false)}
  120. // // </div>
  121. // ),
  122. // },
  123. // {
  124. // id: 'firstname',
  125. // field: 'firstname',
  126. // headerName: 'First Name',
  127. // // sortComparator: dateComparator,
  128. // flex: 2,
  129. // renderCell: (params) => (
  130. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  131. // {params.value}
  132. // </div>
  133. // // <div>
  134. // // {getDateString(params.row.applicationDeadline,false)}
  135. // // </div>
  136. // ),
  137. // },
  138. // {
  139. // id: 'email',
  140. // field: 'email',
  141. // headerName: 'Email',
  142. // flex: 1.5,
  143. // renderCell: (params) => {
  144. // return (
  145. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  146. // {params.value}
  147. // </div>
  148. // );
  149. // }
  150. // },
  151. // {
  152. // id: 'phone1',
  153. // field: 'phone1',
  154. // headerName: 'Phone No.',
  155. // flex: 1,
  156. // renderCell: (params) => {
  157. // return (
  158. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  159. // {params.value}
  160. // </div>
  161. // );
  162. // }
  163. // },
  164. // {
  165. // id: 'phone2',
  166. // field: 'phone2',
  167. // headerName: '2nd Phone No.',
  168. // flex: 1,
  169. // renderCell: (params) => {
  170. // return (
  171. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  172. // {params.value}
  173. // </div>
  174. // );
  175. // }
  176. // },
  177. {
  178. id: 'remarks',
  179. field: 'remarks',
  180. headerName: 'Remarks',
  181. flex: 2,
  182. renderCell: (params) => {
  183. return (
  184. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  185. {params.value}
  186. </div>
  187. );
  188. }
  189. },
  190. ];
  191. return (
  192. <DataGrid
  193. rows={rows}
  194. columns={columns}
  195. columnHeaderHeight={45}
  196. editMode="row"
  197. //autoPageSize
  198. rowModesModel={rowModesModel}
  199. getRowHeight={() => 'auto'}
  200. paginationModel={paginationModel}
  201. onPaginationModelChange={setPaginationModel}
  202. slots={{
  203. noRowsOverlay: () => (
  204. CustomNoRowsOverlay()
  205. )
  206. }}
  207. pageSizeOptions={[10]}
  208. autoHeight
  209. />
  210. );
  211. }