Skip to content

Display a placeholder message if data passed to the grid is empty #28

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 38 additions & 30 deletions src/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,15 @@ var Canvas = React.createClass({
PropTypes.func.isRequired,
PropTypes.array.isRequired
]),
onRows: PropTypes.func
onRows: PropTypes.func,
placeholderText: PropTypes.string
},

render() {
var displayStart = this.state.displayStart;
var displayEnd = this.state.displayEnd;
var rowHeight = this.props.rowHeight;
var length = this.props.length;

var rows = this
.getRows(displayStart, displayEnd)
.map((row, idx) => this.renderRow({
key: displayStart + idx,
ref: idx,
idx: displayStart + idx,
row: row,
height: rowHeight,
columns: this.props.columns,
cellRenderer: this.props.cellRenderer,
isSelected : this.isRowSelected(displayStart + idx),
expandedRows : this.props.expandedRows
}));

this._currentRowsLength = rows.length;

if (displayStart > 0) {
rows.unshift(this.renderPlaceholder('top', displayStart * rowHeight));
}

if (length - displayEnd > 0) {
rows.push(
this.renderPlaceholder('bottom', (length - displayEnd) * rowHeight));
}
var rows = length > 0
? this.getRows()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad line breaking before '?'.

: [<span>{this.props.placeholderText || "There is no data to display"}</span>];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.
Unclosed regular expression.
Unrecoverable syntax error. (17% scanned).


var style = {
position: 'absolute',
Expand Down Expand Up @@ -174,7 +150,39 @@ var Canvas = React.createClass({
}
},

getRows(displayStart, displayEnd) {
getRows() {
var rowHeight = this.props.rowHeight;
var displayStart = this.state.displayStart;
var displayEnd = this.state.displayEnd;

var rows = this.getRowsToDisplay(displayStart, displayEnd)
.map((row, idx) => this.renderRow({
key: displayStart + idx,
ref: idx,
idx: displayStart + idx,
row: row,
height: rowHeight,
columns: this.props.columns,
cellRenderer: this.props.cellRenderer,
isSelected : this.isRowSelected(displayStart + idx),
expandedRows : this.props.expandedRows
}));

this._currentRowsLength = rows.length;

if (displayStart > 0) {
rows.unshift(this.renderPlaceholder('top', displayStart * rowHeight));
}

if (length - displayEnd > 0) {
rows.push(
this.renderPlaceholder('bottom', (length - displayEnd) * rowHeight));
}

return rows;
},

getRowsToDisplay(displayStart, displayEnd) {
this._currentRowsRange = {start: displayStart, end: displayEnd};
if (Array.isArray(this.props.rows)) {
return this.props.rows.slice(displayStart, displayEnd);
Expand Down