Skip to content

Commit

Permalink
Fixes to infinite scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
caguthrie committed May 21, 2015
1 parent 76ebb1f commit 931dfba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
10 changes: 4 additions & 6 deletions build/ReactTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ var ReactTable = React.createClass({displayName: 'ReactTable',
var upperBound = (this.state.rowMultiplier + 1) * this.state.itemsPerScroll;
var rowsToDisplay = [];

if( this.state.rows.length < upperBound ) {
if( this.state.rows.length < upperBound && this.state.rows.length < rasterizedData.length ) {
var lowerBound = this.state.rowMultiplier * this.state.itemsPerScroll;
rowsToDisplay = rasterizedData.slice(lowerBound, upperBound);
this.state.rows = this.state.rows.concat(rowsToDisplay.map(rowMapper, this));
}
else{
else {
rowsToDisplay = rasterizedData.slice(0, upperBound);
this.state.rows = rowsToDisplay.map(rowMapper, this);
}
Expand Down Expand Up @@ -257,15 +257,13 @@ var ReactTable = React.createClass({displayName: 'ReactTable',
if (this.props.disableScrolling)
containerStyle.overflowY = "hidden";

console.log(this.state.rows.length);
return (
React.DOM.div({id: this.state.uniqueId, className: "rt-table-container"},
headers,
React.DOM.div({style: containerStyle, className: "rt-scrollable"},
InfiniteScroll({
loadMore: this.addMoreRows,
hasMore: this.state.hasMore,
loader: React.DOM.div({className: "loader"}, "Loading ...")},
hasMore: this.state.hasMore},
React.DOM.table({className: "rt-table"},
React.DOM.tbody(null,
this.state.rows
Expand Down Expand Up @@ -311,7 +309,7 @@ var Row = React.createClass({displayName: 'Row',
'summary-selected': this.props.isSelected && !this.props.data.isDetail
});
var styles = {
"cursor": this.props.data.isDetail ? "pointer" : "inherit"
"cursor": "pointer"
};
for (var attrname in this.props.extraStyle) {
styles[attrname] = this.props.extraStyle[attrname];
Expand Down
10 changes: 4 additions & 6 deletions dist/react-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,12 @@ var ReactTable = React.createClass({displayName: 'ReactTable',
var upperBound = (this.state.rowMultiplier + 1) * this.state.itemsPerScroll;
var rowsToDisplay = [];

if( this.state.rows.length < upperBound ) {
if( this.state.rows.length < upperBound && this.state.rows.length < rasterizedData.length ) {
var lowerBound = this.state.rowMultiplier * this.state.itemsPerScroll;
rowsToDisplay = rasterizedData.slice(lowerBound, upperBound);
this.state.rows = this.state.rows.concat(rowsToDisplay.map(rowMapper, this));
}
else{
else {
rowsToDisplay = rasterizedData.slice(0, upperBound);
this.state.rows = rowsToDisplay.map(rowMapper, this);
}
Expand Down Expand Up @@ -971,15 +971,13 @@ var ReactTable = React.createClass({displayName: 'ReactTable',
if (this.props.disableScrolling)
containerStyle.overflowY = "hidden";

console.log(this.state.rows.length);
return (
React.DOM.div({id: this.state.uniqueId, className: "rt-table-container"},
headers,
React.DOM.div({style: containerStyle, className: "rt-scrollable"},
InfiniteScroll({
loadMore: this.addMoreRows,
hasMore: this.state.hasMore,
loader: React.DOM.div({className: "loader"}, "Loading ...")},
hasMore: this.state.hasMore},
React.DOM.table({className: "rt-table"},
React.DOM.tbody(null,
this.state.rows
Expand Down Expand Up @@ -1025,7 +1023,7 @@ var Row = React.createClass({displayName: 'Row',
'summary-selected': this.props.isSelected && !this.props.data.isDetail
});
var styles = {
"cursor": this.props.data.isDetail ? "pointer" : "inherit"
"cursor": "pointer"
};
for (var attrname in this.props.extraStyle) {
styles[attrname] = this.props.extraStyle[attrname];
Expand Down
4 changes: 2 additions & 2 deletions dist/react-table.min.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions examples/exporting_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ $(function () {
},
data: testData,
onRightClick: function (row, event) {
console.log(row);
console.log(state);
event.preventDefault();
console.log(row);
console.log(event);
//alert("sweet right click on id " + row.id + "!");
},
height: "300px",
Expand All @@ -89,7 +89,6 @@ $(function () {
onSummarySelectCallback: function (result, state) {
console.log(result);
console.log(state);
console.log("Includes " + result.detailRows.length + " detail rows! state:" + state);
}
};
var table1 = React.render(React.createElement(ReactTable, options), document.getElementById("table"));
Expand Down
10 changes: 4 additions & 6 deletions src/ReactTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ var ReactTable = React.createClass({
var upperBound = (this.state.rowMultiplier + 1) * this.state.itemsPerScroll;
var rowsToDisplay = [];

if( this.state.rows.length < upperBound ) {
if( this.state.rows.length < upperBound && this.state.rows.length < rasterizedData.length ) {
var lowerBound = this.state.rowMultiplier * this.state.itemsPerScroll;
rowsToDisplay = rasterizedData.slice(lowerBound, upperBound);
this.state.rows = this.state.rows.concat(rowsToDisplay.map(rowMapper, this));
}
else{
else {
rowsToDisplay = rasterizedData.slice(0, upperBound);
this.state.rows = rowsToDisplay.map(rowMapper, this);
}
Expand Down Expand Up @@ -257,15 +257,13 @@ var ReactTable = React.createClass({
if (this.props.disableScrolling)
containerStyle.overflowY = "hidden";

console.log(this.state.rows.length);
return (
<div id={this.state.uniqueId} className="rt-table-container">
{headers}
<div style={containerStyle} className="rt-scrollable">
<InfiniteScroll
loadMore={this.addMoreRows}
hasMore={this.state.hasMore}
loader={<div className="loader">Loading ...</div>}>
hasMore={this.state.hasMore}>
<table className="rt-table">
<tbody>
{this.state.rows}
Expand Down Expand Up @@ -311,7 +309,7 @@ var Row = React.createClass({
'summary-selected': this.props.isSelected && !this.props.data.isDetail
});
var styles = {
"cursor": this.props.data.isDetail ? "pointer" : "inherit"
"cursor": "pointer"
};
for (var attrname in this.props.extraStyle) {
styles[attrname] = this.props.extraStyle[attrname];
Expand Down

0 comments on commit 931dfba

Please sign in to comment.