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.
 
 

135 lines
3.5 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. DataGrid,
  5. } from "@mui/x-data-grid";
  6. // ==============================|| EVENT TABLE ||============================== //
  7. export function FiDataGrid({ rows, columns, sx, autoHeight,
  8. hideFooterSelectedRowCount, rowModesModel, editMode,
  9. pageSizeOptions, filterItems,
  10. ...props }) {
  11. const [_rows, set_rows] = React.useState([]);
  12. const [_columns, set_columns] = React.useState([]);
  13. const [_rowModesModel, set_rowModesModel] = React.useState({});
  14. const [_editMode, set_editMode] = React.useState("row");
  15. const [_pageSizeOptions, set_pageSizeOptions] = React.useState([10, 25, 50]);
  16. const [_filterItems, set_filterItems] = React.useState([]);
  17. const [_autoHeight, set_autoHeight] = React.useState(true);
  18. const [myHideFooterSelectedRowCount, setMyHideFooterSelectedRowCount] = React.useState(true);
  19. const [_sx, set_sx] = React.useState({
  20. padding: "4 2 4 2",
  21. // boxShadow: 1,
  22. // border: 1,
  23. // borderColor: '#DDD',
  24. '& .MuiDataGrid-cell': {
  25. borderTop: 1,
  26. borderBottom: 1,
  27. borderColor: "#EEE",
  28. },
  29. '& .MuiDataGrid-footerContainer': {
  30. border: 1,
  31. borderColor: "#EEE"
  32. },
  33. });
  34. React.useEffect(() => {
  35. if (sx) {
  36. set_sx(sx);
  37. }
  38. if (hideFooterSelectedRowCount) {
  39. setMyHideFooterSelectedRowCount(hideFooterSelectedRowCount);
  40. }
  41. if (rowModesModel) {
  42. set_rowModesModel(rowModesModel)
  43. }
  44. if (rows) {
  45. set_rows(rows)
  46. }
  47. if (columns) {
  48. set_columns(columns)
  49. }
  50. if (pageSizeOptions) {
  51. set_pageSizeOptions(pageSizeOptions)
  52. }
  53. if(autoHeight != undefined){
  54. set_autoHeight(autoHeight)
  55. }
  56. if(editMode){
  57. set_editMode(editMode);
  58. }
  59. }, []);
  60. React.useEffect(() => {
  61. if (sx) {
  62. set_sx(sx);
  63. }
  64. }, [sx]);
  65. React.useEffect(() => {
  66. if (hideFooterSelectedRowCount) {
  67. setMyHideFooterSelectedRowCount(hideFooterSelectedRowCount);
  68. }
  69. }, [hideFooterSelectedRowCount]);
  70. React.useEffect(() => {
  71. if (rowModesModel) {
  72. set_rowModesModel(rowModesModel)
  73. }
  74. }, [rowModesModel]);
  75. React.useEffect(() => {
  76. if (rows) {
  77. set_rows(rows)
  78. }
  79. }, [rows]);
  80. React.useEffect(() => {
  81. if (columns) {
  82. set_columns(columns)
  83. }
  84. }, [columns]);
  85. React.useEffect(() => {
  86. if (pageSizeOptions) {
  87. set_pageSizeOptions(pageSizeOptions)
  88. }
  89. }, [pageSizeOptions]);
  90. React.useEffect(() => {
  91. if(autoHeight != undefined){
  92. set_autoHeight(autoHeight)
  93. }
  94. }, [autoHeight]);
  95. React.useEffect(() => {
  96. if(editMode){
  97. set_editMode(editMode);
  98. }
  99. }, [editMode]);
  100. React.useEffect(() => {
  101. if(filterItems){
  102. set_filterItems(filterItems);
  103. }
  104. }, [filterItems]);
  105. return (
  106. <DataGrid
  107. {...props}
  108. rows={_rows}
  109. columns={_columns}
  110. rowModesModel={_rowModesModel}
  111. pageSizeOptions={_pageSizeOptions}
  112. editMode={_editMode}
  113. autoHeight={_autoHeight}
  114. hideFooterSelectedRowCount={myHideFooterSelectedRowCount}
  115. filterModel={{items:_filterItems}}
  116. sx={_sx}
  117. />
  118. );
  119. }