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.
 
 

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