Skip to content

Commit

Permalink
fix broken responsive 'scroll' option #34
Browse files Browse the repository at this point in the history
* The responsive: scroll option looked terrible. Made it look good and made headers and footers fixed.

* Fixed the weird tooptip scrolling issue

* Figured it out. I'm a little surprised that I was able to do this. Hooray for JSS!
  • Loading branch information
tgBryanBailes authored and gregnb committed Apr 18, 2018
1 parent f6e5090 commit 31c366c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 40 deletions.
2 changes: 1 addition & 1 deletion examples/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Example extends React.Component {
const options = {
filter: true,
filterType: 'dropdown',
responsive: 'stacked',
responsive: 'scroll',
};

return (
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>MUIDatables Example</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
<div id="app-root">
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 26 additions & 22 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { withStyles } from "material-ui/styles";
const defaultTableStyles = {
root: {},
responsiveScroll: {
display: "block",
overflowX: "auto",
},
caption: {
Expand Down Expand Up @@ -540,7 +539,7 @@ class MUIDataTable extends React.Component {
<Paper
elevation={4}
ref={el => (this.tableContent = el)}
className={this.options.responsive === "scroll" ? classes.responsiveScroll : null}>
>
{selectedRows.length ? (
<MUIDataTableToolbarSelect
options={this.options}
Expand All @@ -563,33 +562,38 @@ class MUIDataTable extends React.Component {
/>
)}
<MUIDataTableFilterList options={this.options} filterList={filterList} filterUpdate={this.filterUpdate} />
<Table ref={el => (this.tableRef = el)} tabIndex={"0"} role={"grid"} aria-readonly={"true"}>
<caption className={classes.caption}>{title}</caption>
<MUIDataTableHead
columns={columns}
handleHeadUpdateRef={fn => (this.updateToolbarSelect = fn)}
selectRowUpdate={this.selectRowUpdate}
toggleSort={this.toggleSortColumn}
options={this.options}
/>
<MUIDataTableBody
data={this.state.displayData}
columns={columns}
page={page}
rowsPerPage={rowsPerPage}
selectedRows={selectedRows}
selectRowUpdate={this.selectRowUpdate}
options={this.options}
searchText={searchText}
filterList={filterList}
/>
<div className={this.options.responsive === "scroll" ? classes.responsiveScroll : null}>
<Table ref={el => (this.tableRef = el)} tabIndex={"0"} role={"grid"} >
<caption className={classes.caption}>{title}</caption>
<MUIDataTableHead
columns={columns}
handleHeadUpdateRef={fn => (this.updateToolbarSelect = fn)}
selectRowUpdate={this.selectRowUpdate}
toggleSort={this.toggleSortColumn}
options={this.options}
/>
<MUIDataTableBody
data={this.state.displayData}
columns={columns}
page={page}
rowsPerPage={rowsPerPage}
selectedRows={selectedRows}
selectRowUpdate={this.selectRowUpdate}
options={this.options}
searchText={searchText}
filterList={filterList}
/>
</Table>
</div>
<Table>
{this.options.pagination ? (
<MUIDataTablePagination
count={displayData.length}
page={page}
rowsPerPage={rowsPerPage}
changeRowsPerPage={this.changeRowsPerPage}
changePage={this.changePage}
component="div"
options={this.options}
/>
) : (
Expand Down
7 changes: 5 additions & 2 deletions src/MUIDataTableBodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { withStyles } from "material-ui/styles";

const defaultBodyCellStyles = {
root: {},
cellStacked: {
cellHide: {
display: "none",
},
cellStacked: {
"@media screen and (max-width: 960px)": {
display: "inline-block",
backgroundColor: "#FFF",
Expand Down Expand Up @@ -36,7 +38,8 @@ class MUIDataTableBodyCell extends React.Component {
key={1}
className={classNames({
[classes.root]: true,
[classes.cellStacked]: true,
[classes.cellHide]: true,
[classes.cellStacked]: options.responsive === "stacked",
})}>
{columnHeader}
</TableCell>,
Expand Down
2 changes: 1 addition & 1 deletion src/MUIDataTableHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MUIDataTableHead extends React.Component {
const { selectChecked } = this.state;

return (
<TableHead className={classNames({ [classes.responsiveStacked]: true, [classes.main]: true })}>
<TableHead className={classNames({ [classes.responsiveStacked]: options.responsive==="stacked", [classes.main]: true })}>
<MUIDataTableHeadRow>
{options.selectableRows ? (
<MUIDataTableSelectCell onChange={this.handleRowSelect.bind(null)} checked={selectChecked} />
Expand Down
7 changes: 6 additions & 1 deletion src/MUIDataTableHeadCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const defaultHeadCellStyles = {
tooltip: {
cursor: "pointer",
},
mypopper: {
"&[data-x-out-of-boundaries]": {
display: "none",
}
},
data: {
display: "inline-block",
},
Expand Down Expand Up @@ -57,7 +62,7 @@ class MUIDataTableHeadCell extends React.Component {
return (
<TableCell className={classes.root} scope={"col"} sortDirection={sortDirection}>
{options.sort ? (
<Tooltip title="Sort" placement={"bottom-end"} className={classes.tooltip} enterDelay={300}>
<Tooltip title="Sort" placement={"bottom-end"} className={classes.tooltip} enterDelay={300} classes={{ popper: classes.mypopper }}>
<span
role="button"
onKeyUp={this.handleClickSort}
Expand Down
24 changes: 13 additions & 11 deletions src/MUIDataTableToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MUIDataTableToolbar extends React.Component {
constructor(props) {
super(props);

if (props.options.responsive && props.options.responsive === "stacked") {
if (props.options.responsive) {
this.tbarStyles = merge(defaultToolbarStyles, responsiveToolbarStyles);
} else {
this.tbarStyles = defaultToolbarStyles;
Expand Down Expand Up @@ -194,16 +194,18 @@ class MUIDataTableToolbar extends React.Component {
false
)}
{options.print ? (
<ReactToPrint
trigger={() => (
<Tooltip title="Print">
<IconButton aria-label="Print" classes={{ root: toolbarStyles.icon }}>
<PrintIcon />
</IconButton>
</Tooltip>
)}
content={() => this.props.tableRef()}
/>
<Tooltip title="Print">
<span>
<ReactToPrint
trigger={() => (
<IconButton aria-label="Print" classes={{ root: toolbarStyles.icon }}>
<PrintIcon />
</IconButton>
)}
content={() => this.props.tableRef()}
/>
</span>
</Tooltip>
) : (
false
)}
Expand Down

0 comments on commit 31c366c

Please sign in to comment.