Skip to content

Commit

Permalink
Fix: Add new rows if isScrollable=false
Browse files Browse the repository at this point in the history
  • Loading branch information
denisraslov committed Jul 31, 2022
1 parent 529825b commit 451bbd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/scrollWrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ class SpreadsheetGridScrollWrapper extends React.PureComponent {
}

render() {
const rows = slice(this.props.rows, this.state.first, this.state.last)
const rows = this.props.isScrollable
? slice(this.props.rows, this.state.first, this.state.last)
: this.props.rows

return (
<div className='SpreadsheetGridContainer' ref={this.tableEl}>
Expand Down
45 changes: 30 additions & 15 deletions stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Grid, Input, Select } from './../index'
const rows = []
const positions = []

for (let i = 0; i < 1000; i++) {
for (let i = 0; i < 10; i++) {
rows.push({
id: i,
firstName: 'First name ' + i,
Expand All @@ -32,6 +32,18 @@ function DataTable(props) {
setRows([].concat(rows))
}

const addRow = () => {
const id = [...rows][rows.length - 1].id + 1
const newRow = {
id: id,
firstName: 'First name ' + i,
secondName: 'Second name ' + i,
positionId: 3,
}

setRows(rows.concat(newRow))
}

const initColumns = () => {
return [
{
Expand Down Expand Up @@ -103,20 +115,23 @@ function DataTable(props) {
}

return (
<div className='DataTable'>
<Grid
columns={columns}
rows={rows}
getRowKey={(row) => row.id}
rowHeight={50}
isColumnsResizable
onColumnResize={onColumnResize}
focusOnSingleClick={props.focusOnSingleClick}
disabledCellChecker={(row, columnId) => {
return columnId === 'age'
}}
isScrollable={props.isScrollable}
/>
<div>
<button onClick={addRow}>Add row</button>
<div className='DataTable'>
<Grid
columns={columns}
rows={rows}
getRowKey={(row) => row.id}
rowHeight={50}
isColumnsResizable
onColumnResize={onColumnResize}
focusOnSingleClick={props.focusOnSingleClick}
disabledCellChecker={(row, columnId) => {
return columnId === 'age'
}}
isScrollable={props.isScrollable}
/>
</div>
</div>
)
}
Expand Down

0 comments on commit 451bbd5

Please sign in to comment.