Skip to content

Commit 9107a9a

Browse files
committed
Add a loading option
1 parent f0ea9e5 commit 9107a9a

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/MUIDataTable.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import TableToolbar from './components/TableToolbar';
1818
import TableToolbarSelect from './components/TableToolbarSelect';
1919
import textLabels from './textLabels';
2020
import { buildMap, getCollatorComparator, sortCompare } from './utils';
21+
import LoaderOverlay from './components/LoaderOverlay';
2122

2223
const defaultTableStyles = theme => ({
2324
root: {},
24-
paper: {},
25+
paper: {
26+
position: 'relative'
27+
},
2528
tableRoot: {
2629
outline: 'none',
2730
},
@@ -141,6 +144,7 @@ class MUIDataTable extends React.Component {
141144
customToolbarSelect: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
142145
customFooter: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
143146
customSearchRender: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
147+
loading: PropTypes.bool,
144148
customRowRender: PropTypes.func,
145149
onRowClick: PropTypes.func,
146150
onRowsSelect: PropTypes.func,
@@ -285,6 +289,7 @@ class MUIDataTable extends React.Component {
285289
selectableRowsOnClick: false,
286290
selectableRowsHeader: true,
287291
caseSensitive: false,
292+
loading: false,
288293
serverSide: false,
289294
rowHover: true,
290295
fixedHeader: true,
@@ -1338,6 +1343,9 @@ class MUIDataTable extends React.Component {
13381343
changeRowsPerPage={this.changeRowsPerPage}
13391344
changePage={this.changePage}
13401345
/>
1346+
{
1347+
this.options.loading && <LoaderOverlay />
1348+
}
13411349
<div className={classes.liveAnnounce} aria-live={'polite'}>
13421350
{announceText}
13431351
</div>

src/components/LoaderOverlay.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { withStyles } from '@material-ui/core/styles';
3+
import CircularProgress from '@material-ui/core/CircularProgress';
4+
import { fade } from '@material-ui/core/styles/colorManipulator';
5+
6+
const styles = theme => ({
7+
overlay: {
8+
position: 'absolute',
9+
top: 0,
10+
left: 0,
11+
zIndex: 110,
12+
display: 'flex',
13+
width: '100%',
14+
height: '100%',
15+
backgroundColor: fade(theme.palette.background.paper, 0.7)
16+
},
17+
progressContainer: {
18+
margin: 'auto'
19+
}
20+
})
21+
22+
class LoaderOverlay extends React.Component {
23+
render() {
24+
const { classes } = this.props;
25+
return(
26+
<div className={classes.overlay}>
27+
<div className={classes.progressContainer}>
28+
<CircularProgress />
29+
</div>
30+
</div>
31+
)
32+
}
33+
}
34+
35+
export default withStyles(styles, { withTheme: true })(LoaderOverlay);

test/MUIDataTable.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ describe('<MUIDataTable />', function() {
8484
);
8585
});
8686

87+
it('should render a loader', () => {
88+
const wrapper = mount(<MUIDataTable columns={columns} data={data} options={{ loading: true }} />);
89+
assert.equal(wrapper.find('LoaderOverlay').length, 1)
90+
});
91+
8792
it('should correctly build internal columns data structure', () => {
8893
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
8994
const actualResult = shallowWrapper.dive().state().columns;

0 commit comments

Comments
 (0)