Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

106 linhas
2.9 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/Visibility';
  8. import {useEffect} from "react";
  9. import {useNavigate} from "react-router-dom";
  10. import * as DateUtils from "utils/DateUtils";
  11. // ==============================|| EVENT TABLE ||============================== //
  12. export default function OrganizationTable({recordList}) {
  13. const [rows, setRows] = React.useState(recordList);
  14. const [rowModesModel] = React.useState({});
  15. const navigate = useNavigate()
  16. useEffect(() => {
  17. setRows(recordList);
  18. }, [recordList]);
  19. const handleActionClick = (id) => () => {
  20. navigate('/org/'+ id);
  21. };
  22. const columns = [
  23. {
  24. field: 'actions',
  25. type: 'actions',
  26. headerName: 'Actions',
  27. width: 100,
  28. cellClassName: 'actions',
  29. getActions: ({id}) => {
  30. return [
  31. <GridActionsCellItem
  32. key="OutSave"
  33. icon={<EditIcon/>}
  34. label="Edit"
  35. className="textPrimary"
  36. onClick={handleActionClick(id)}
  37. color="primary"
  38. />]
  39. },
  40. },
  41. {
  42. id: 'brNo',
  43. field: 'brNo',
  44. headerName: 'BR No.',
  45. flex: 1,
  46. },
  47. {
  48. id: 'enCompanyName',
  49. field: 'enCompanyName',
  50. headerName: 'Name (Eng)',
  51. flex: 1,
  52. },
  53. {
  54. id: 'chCompanyName',
  55. field: 'chCompanyName',
  56. headerName: 'Name (Ch)',
  57. flex: 1,
  58. },
  59. {
  60. id: 'contactTel',
  61. field: 'contactTel',
  62. headerName: 'Tel.',
  63. flex: 1,
  64. renderCell: (params) => {
  65. let phone = JSON.parse(params.value);
  66. let contact = "";
  67. if (phone && phone.phoneNumber) {
  68. contact = phone?.countryCode + " " + phone?.phoneNumber
  69. }
  70. return contact;
  71. }
  72. },
  73. {
  74. id: 'brExpiryDate',
  75. field: 'brExpiryDate',
  76. headerName: 'Expiry Date',
  77. flex: 1,
  78. valueGetter:(params)=>{
  79. return DateUtils.dateStr(params?.value);
  80. }
  81. },
  82. ];
  83. return (
  84. <div style={{height: 400, width: '100%'}}>
  85. <DataGrid
  86. rows={rows}
  87. columns={columns}
  88. editMode="row"
  89. rowModesModel={rowModesModel}
  90. initialState={{
  91. pagination: {
  92. paginationModel: {page: 0, pageSize: 5},
  93. },
  94. }}
  95. pageSizeOptions={[5, 10]}
  96. autoHeight
  97. />
  98. </div>
  99. );
  100. }