refactor: Bring back Material DataGrid
Fix the column resize bugs that made it previously unusable
This commit is contained in:
1 parent
727e6a94e6
commit
d20580cebb
2 files changed
+23
-9
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { ThemeProvider, CssBaseline, GlobalStyles } from '@mui/material';
|
||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||
import QueryControl from './QueryControl';
|
||||
import ReactDataGrid from './ReactDataGrid';
|
||||
import DataTable from './DataTable';
|
||||
import { useState, useEffect } from 'react';
|
||||
import useWebSocket, { ReadyState } from 'react-use-websocket';
|
||||
import Sidebar from './SideBar';
|
||||
@@ -165,7 +165,7 @@ const App = () => {
|
||||
queryError != null
|
||||
? <ErrorView error={queryError} />
|
||||
: (hasData
|
||||
? <ReactDataGrid columns={blueTable.columns} rows={blueTable.rows ?? []} />
|
||||
? <DataTable columns={blueTable?.columns} rows={blueTable?.rows ?? []} sx={{ margin: theme.spacing(2) }} />
|
||||
: <Alert severity="info" sx={{margin: theme.spacing(2)}}>
|
||||
<AlertTitle>No data received.</AlertTitle>
|
||||
<p>Enter query, then click Play</p>
|
||||
|
||||
@@ -1,23 +1,37 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { DataGrid } from '@mui/x-data-grid';
|
||||
import './DataGrid.css'
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
function getGridColDef(col) {
|
||||
return {
|
||||
field: col.name,
|
||||
headerName: col.name,
|
||||
export default function DataTable({ columns, rows }) {
|
||||
const [columnWidths, setColumnWidths] = useState({});
|
||||
|
||||
const handleColumnResize = (params) => {
|
||||
const newWidth = params.width;
|
||||
setColumnWidths((prevWidths) => ({
|
||||
...prevWidths,
|
||||
[params.colDef.field]: params.width,
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
export default function DataTable({ columns, rows, apiRef }) {
|
||||
const getGridColDef = useMemo(() => {
|
||||
return col => {
|
||||
return {
|
||||
field: col.name,
|
||||
headerName: col.name,
|
||||
width: columnWidths[col.name],
|
||||
};
|
||||
}
|
||||
}, [columnWidths]);
|
||||
|
||||
return (
|
||||
<DataGrid
|
||||
className='data-grid-container'
|
||||
autosizeOnMount={false}
|
||||
columns={columns?.map(getGridColDef) ?? []}
|
||||
onColumnResize={handleColumnResize}
|
||||
rows={rows ?? []}
|
||||
sx={{
|
||||
tableLayout: "auto",
|
||||
borderColor: 'primary.main',
|
||||
backgroundColor: 'primary.dark',
|
||||
color: 'text.primary',
|
||||
|
||||
Reference in new issue
Block a user