您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

78 行
2.4 KiB

  1. // material-ui
  2. import {
  3. DataGrid,
  4. } from "@mui/x-data-grid";
  5. import {useEffect, useState} from "react";
  6. import axios from "axios";
  7. import {apiPath} from "../../../auth/utils";
  8. import * as React from "react";
  9. import {GET_GROUP_COMBO_PATH} from "../../../utils/ApiPathConst";
  10. import Loadable from 'components/Loadable';
  11. import { lazy } from 'react';
  12. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  13. // ==============================|| EVENT TABLE ||============================== //
  14. export default function UserGroupTable({setSelectedRow, userGroup,isNewRecord}) {
  15. const [groupData, setGroupData] = useState([]);
  16. const [onReady, setOnReady] = useState(false);
  17. const [currentSelectedRow, setCurrentSelectedRow] = useState(userGroup);
  18. useEffect(() => {
  19. axios.get(`${apiPath}${GET_GROUP_COMBO_PATH}`)
  20. .then((response) => {
  21. if (response.status === 200) {
  22. setGroupData(response.data.records);
  23. }
  24. })
  25. .catch(error => {
  26. console.log(error);
  27. return false;
  28. });
  29. }, []);
  30. useEffect(() => {
  31. //if state data are ready and assign to different field
  32. if (groupData.length > 0||isNewRecord) {
  33. setOnReady(true);
  34. }
  35. }, [groupData]);
  36. const columns = [
  37. {
  38. id: 'group',
  39. field: 'name',
  40. headerName: 'Group',
  41. flex: 1,
  42. editable: true,
  43. },
  44. ];
  45. return (
  46. !onReady ?
  47. <LoadingComponent/>
  48. :
  49. <div style={{height: '100%', width: '100%'}}>
  50. <DataGrid
  51. rows={groupData}
  52. columns={columns}
  53. editMode="row"
  54. initialState={{
  55. pagination: {
  56. paginationModel: {page: 0, pageSize: 3},
  57. },
  58. }}
  59. pageSizeOptions={[3, 5]}
  60. checkboxSelection
  61. rowSelectionModel={currentSelectedRow}
  62. onRowSelectionModelChange={(ids) => {
  63. console.log(ids);
  64. setSelectedRow(ids);
  65. setCurrentSelectedRow(ids);
  66. }}
  67. autoHeight
  68. />
  69. </div>
  70. );
  71. }