Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a loading option #958

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/MUIDataTable.js
Expand Up @@ -18,10 +18,13 @@ import TableToolbar from './components/TableToolbar';
import TableToolbarSelect from './components/TableToolbarSelect';
import textLabels from './textLabels';
import { buildMap, getCollatorComparator, sortCompare } from './utils';
import LoaderOverlay from './components/LoaderOverlay';

const defaultTableStyles = theme => ({
root: {},
paper: {},
paper: {
position: 'relative'
},
tableRoot: {
outline: 'none',
},
Expand Down Expand Up @@ -141,6 +144,7 @@ class MUIDataTable extends React.Component {
customToolbarSelect: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
customFooter: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
customSearchRender: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
loading: PropTypes.bool,
customRowRender: PropTypes.func,
onRowClick: PropTypes.func,
onRowsSelect: PropTypes.func,
Expand Down Expand Up @@ -285,6 +289,7 @@ class MUIDataTable extends React.Component {
selectableRowsOnClick: false,
selectableRowsHeader: true,
caseSensitive: false,
loading: false,
serverSide: false,
rowHover: true,
fixedHeader: true,
Expand Down Expand Up @@ -1338,6 +1343,9 @@ class MUIDataTable extends React.Component {
changeRowsPerPage={this.changeRowsPerPage}
changePage={this.changePage}
/>
{
this.options.loading && <LoaderOverlay />
}
<div className={classes.liveAnnounce} aria-live={'polite'}>
{announceText}
</div>
Expand Down
35 changes: 35 additions & 0 deletions src/components/LoaderOverlay.js
@@ -0,0 +1,35 @@
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
import CircularProgress from '@material-ui/core/CircularProgress';
import { fade } from '@material-ui/core/styles/colorManipulator';

const styles = theme => ({
overlay: {
position: 'absolute',
top: 0,
left: 0,
zIndex: 110,
display: 'flex',
width: '100%',
height: '100%',
backgroundColor: fade(theme.palette.background.paper, 0.7)
},
progressContainer: {
margin: 'auto'
}
})

class LoaderOverlay extends React.Component {
render() {
const { classes } = this.props;
return(
<div className={classes.overlay}>
<div className={classes.progressContainer}>
<CircularProgress />
</div>
</div>
)
}
}

export default withStyles(styles, { withTheme: true })(LoaderOverlay);
5 changes: 5 additions & 0 deletions test/MUIDataTable.test.js
Expand Up @@ -84,6 +84,11 @@ describe('<MUIDataTable />', function() {
);
});

it('should render a loader', () => {
const wrapper = mount(<MUIDataTable columns={columns} data={data} options={{ loading: true }} />);
assert.equal(wrapper.find('LoaderOverlay').length, 1)
});

it('should correctly build internal columns data structure', () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const actualResult = shallowWrapper.dive().state().columns;
Expand Down