-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Table] pagination / infinite scrolling #1511
Comments
If you're interested in infinite scrolling, I would take a look at: https://github.com/facebook/fixed-data-table. Might find some inspiration there. If you want to pursue pagination I would suggest creating the pagination UI; next/prev buttons, page number buttons with an ellipsis and provide a callback that simply communicates what page was selected. This will allow something like redux to be utilized for the paging and then the consumer of the table can populate it with the new table rows. What do you think? |
My rough idea is that the |
The infinite scroll is best implemented when you have all of the data and can control the heights of each row. Currently, we do not enforce a specific row height so determining how many rows to insert at a given point becomes more complicated. My vote would be to keep the table simple and provide paging hooks -- or, create a decorator that will wrap a table and provide pagination controls. See https://www.google.com/design/spec/components/data-tables.html#data-tables-tables-within-cards for an example of the paging controls. |
I see, thanks for sharing! |
@jkruder @zachguo I have implemented infinite scrolling as a prop 'infiniteScroll' with true or false acceptance and 'infiniteScrollOffset' which accepts a number indicating at many pixels from the bottom of the table should more rows be loaded on scroll. I am passing mapped state items as children to the tableBody which creates the TableRows based on the 'page' set by scroll position, but I believe I can move all this logic to within the tableBody component itself. I will submit a PR for this soon. Thanks |
You could also try https://github.com/orgsync/react-list for the infinit scroll. |
When do you plan to do pagination? |
@kodermax logics for pagination can be handled by user outside MUI. For creating a table footer similar to the specs of material design you can try following code snippet. // footer.jsx
import React from 'react';
import {TableFooter as TF, TableRow, TableRowColumn, FontIcon, IconButton} from 'material-ui';
const styles = {
footerContent: {
float: 'right'
},
footerText: {
float: 'right',
paddingTop: 16,
height: 16
}
};
const TableFooter = React.createClass({
propTypes: {
offset: React.PropTypes.number.isRequired, // current offset
total: React.PropTypes.number.isRequired, // total number of rows
limit: React.PropTypes.number.isRequired, // num of rows in each page
onPageClick: React.PropTypes.func // what to do after clicking page number
},
render() {
let offset = this.props.offset;
let total = this.props.total;
let limit = this.props.limit;
return (
<TF adjustForCheckbox={false}>
<TableRow>
<TableRowColumn style={styles.footerContent}>
<IconButton disabled={offset === 0} onClick={this.props.onPageClick.bind(null, offset - limit)}>
<FontIcon className="material-icons">chevron_left</FontIcon>
</IconButton>
<IconButton disabled={offset + limit >= total} onClick={this.props.onPageClick.bind(null, offset + limit)}>
<FontIcon className="material-icons">chevron_right</FontIcon>
</IconButton>
</TableRowColumn>
<TableRowColumn style={styles.footerText}>
{Math.min((offset + 1), total) + '-' + Math.min((offset + limit), total) + ' of ' + total}
</TableRowColumn>
</TableRow>
</TF>
);
}
});
export default TableFooter; |
@zachguo That looks good. Do you think we could add it to the lib? |
I can do a PR if users find it helpful. |
send PR, we will improve |
I'd be interested in a pagination implementation. Been trying out the footer bit @zachguo posted and it looks good. |
@zachguo since the changes in v15.0 pertaining to module imports, my module loading approach would not render the TableFooter component. I couldn't find a suitable workaround for that so instead I slightly modified the structure of your component, see below for anyone interested in using.
Including the component as so:
I couldn't determine what was causing your component not to render - I believe it might be some sort of namespacing collision with the module loading approach. I'd be curious to hear any possible culprits. Thanks anyway. |
So based on implementation given by @zachguo I was able to add pagination and it works just fine. Thanks for your comments. Following is the complete implementation code (except for methods):
|
@rs6g10 - that looks like a docs example in the making. Care to submit a PR? |
@Dombo I upgraded MUI to v0.15 today and ran into same issue. I don't know what happened, thanks for your workaround. |
@Dombo hmm, even your workaround didn't work for me. What I got is just an empty Actually no matter what I put into
got ignored.... Do you know why? |
@zachguo I also struggled with that issue - my guess is that it's related to the TableRow component.
Specifically
Is my PagiFooter somehow not a valid react element? |
@Dombo Thanks for your reply! I don't think that's the case, it didn't work even if I simply put a string inside |
@Dombo @zachguo i figured it out. When you create a custom component wrapping
class MyCustomTableFooter extends React.Component {
render() {
return (
<TableRow>
<TableRowColumn>
<h1>This is my custom table footer</h1>
</TableRowColumn>
</TableRow>
);
}
}
MyCustomTableFooter.muiName = 'TableFooter'; |
@zachguo In the next major version we'll be including a regular table and an example of a material styled infinite/virtualized data grid component. |
@nathanhere and when you plan to release new major version? |
Meanwhile I'll just leave this here https://github.com/ultimate-pagination/react-ultimate-pagination-material-ui |
@Dombo Could you post your method to calculate the offset? |
has anyone made any progress for infinite horizontal scroll? |
I gonna close this, guys. Few takeaways from this thread:
If you are open to design specs other than Material Design, take a look at Ant Design's table component. |
@jkruder In addition to sorting, we would love to give this a shot, too. Do you have any suggestion about implementation?
The text was updated successfully, but these errors were encountered: