I have a data table where I declare rows and columns as simple variables, making it difficult to style them using 'style={{textAlign: center}}'. I tried adding a CSS file, but it did not work with the Material UI table. I am unsure of how to proceed. Here is my code:
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';
export default function DataTable({data, someColumns}) {
const columns = someColumns;
const rows = data;
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid rows={rows} columns={columns} pageSize={5} checkboxSelection />
</div>
);
}
The data in the columns defaults to being aligned left. How can I change this?
EDIT: I was able to fix it using this CSS. Thanks to Fahad.
.MuiDataGrid-colCellTitle {
display: block;
text-align:center;
width: 100%;
}
.MuiDataGrid-cell {
display: block;
position: relative;
text-align: center;
}
This CSS will center both rows and columns in the table.