Skip to content

Commit

Permalink
Fixed #616
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Nov 7, 2018
1 parent 132bb19 commit 76f9137
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/datatable/BodyRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class BodyRow extends Component {

return (
<tr ref={(el) => {this.container = el;}} className={className} onClick={this.onClick} onDoubleClick={this.onDoubleClick} onTouchEnd={this.onTouchEnd} onContextMenu={this.onRightClick} onMouseDown={this.onMouseDown}
onDragStart={this.props.onDragStart} onDragEnd={this.onDragEnd} onDragOver={this.onDragOver} onDragLeave={this.onDragLeave} onDrop={this.onDrop}>
onDragStart={this.props.onDragStart} onDragEnd={this.onDragEnd} onDragOver={this.onDragOver} onDragLeave={this.onDragLeave} onDrop={this.onDrop} style={{height: this.props.virtualRowHeight}}>
{cells}
</tr>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/datatable/DataTable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface DataTableProps {
scrollHeight?: string;
virtualScroll?: boolean;
virtualScrollDelay?: number;
virtualRowHeight?: number;
frozenWidth?: string;
frozenValue?: any[];
csvSeparator?: string;
Expand Down
6 changes: 4 additions & 2 deletions src/components/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class DataTable extends Component {
scrollHeight: null,
virtualScroll: false,
virtualScrollDelay: 250,
virtualRowHeight: 28,
frozenWidth: null,
frozenValue: null,
csvSeparator: ',',
Expand Down Expand Up @@ -140,6 +141,7 @@ export class DataTable extends Component {
scrollHeight: PropTypes.string,
virtualScroll: PropTypes.bool,
virtualScrollDelay: PropTypes.number,
virtualRowHeight: PropTypes.number,
frozenWidth: PropTypes.string,
frozenValue: PropTypes.array,
csvSeparator: PropTypes.string,
Expand Down Expand Up @@ -882,7 +884,7 @@ export class DataTable extends Component {
contextMenuSelection={this.props.contextMenuSelection} onContextMenuSelectionChange={this.props.onContextMenuSelectionChange} onContextMenu={this.props.onContextMenu}
expandedRows={this.props.expandedRows} onRowToggle={this.props.onRowToggle} rowExpansionTemplate={this.props.rowExpansionTemplate}
onRowExpand={this.props.onRowExpand} responsive={this.props.responsive} emptyMessage={this.props.emptyMessage}
virtualScroll={this.props.virtualScroll}
virtualScroll={this.props.virtualScroll} virtualRowHeight={this.props.virtualRowHeight}
groupField={this.props.groupField} rowGroupMode={this.props.rowGroupMode} rowGroupHeaderTemplate={this.props.rowGroupHeaderTemplate} rowGroupFooterTemplate={this.props.rowGroupFooterTemplate}
sortField={this.getSortField()} rowClassName={this.props.rowClassName} onRowReorder={this.props.onRowReorder}>
{columns}
Expand All @@ -901,7 +903,7 @@ export class DataTable extends Component {
body={this.createTableBody(value, columns)} frozenBody={this.props.frozenValue ? this.createTableBody(this.props.frozenValue, columns): null}
footer={this.createTableFooter(columns, footerColumnGroup)}
scrollHeight={this.props.scrollHeight} frozen={frozen} frozenWidth={this.props.frozenWidth}
virtualScroll={this.props.virtualScroll} rows={this.props.rows} totalRecords={totalRecords}
virtualScroll={this.props.virtualScroll} virtualRowHeight={this.props.virtualRowHeight} rows={this.props.rows} totalRecords={totalRecords}
onVirtualScroll={this.onVirtualScroll} loading={this.props.loading}></ScrollableView>
}

Expand Down
14 changes: 4 additions & 10 deletions src/components/datatable/ScrollableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ScrollableView extends Component {
frozenWidth: null,
frozenBody: null,
virtualScroll: false,
virtualRowHeight: null,
rows: null,
totalRecords: null,
loading: false,
Expand All @@ -29,6 +30,7 @@ export class ScrollableView extends Component {
frozenWidth: PropTypes.string,
frozenBody: PropTypes.element,
virtualScroll: PropTypes.bool,
virtualRowHeight: PropTypes.number,
rows: PropTypes.number,
totalRcords: PropTypes.number,
loading: PropTypes.bool,
Expand Down Expand Up @@ -57,8 +59,7 @@ export class ScrollableView extends Component {
this.alignScrollBar();

if(this.props.virtualScroll) {
this.calculateRowHeight();
this.virtualScroller.style.height = this.props.totalRecords * this.rowHeight + 'px';
this.virtualScroller.style.height = this.props.totalRecords * this.props.virtualRowHeight + 'px';
}
}

Expand Down Expand Up @@ -126,7 +127,7 @@ export class ScrollableView extends Component {
if(this.props.virtualScroll) {
let viewport = DomHandler.getOuterHeight(this.scrollBody);
let tableHeight = DomHandler.getOuterHeight(this.scrollTable);
let pageHeight = this.rowHeight * this.props.rows;
let pageHeight = this.props.virtualRowHeight * this.props.rows;
let virtualTableHeight = DomHandler.getOuterHeight(this.virtualScroller);
let pageCount = (virtualTableHeight / pageHeight)||1;

Expand Down Expand Up @@ -157,13 +158,6 @@ export class ScrollableView extends Component {
this.scrollFooterBox.style.marginRight = scrollBarWidth + 'px';
}
}

calculateRowHeight() {
let row = DomHandler.findSingle(this.scrollTable, 'tr:not(.p-datatable-emptymessage-row)');
if(row) {
this.rowHeight = DomHandler.getOuterHeight(row);
}
}

renderColGroup() {
if(this.props.columns && this.props.columns.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/datatable/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class TableBody extends Component {
onRadioClick={this.onRadioClick} onCheckboxClick={this.onCheckboxClick} selected={selected} contextMenuSelected={contextMenuSelected} rowClassName={this.props.rowClassName}
sortField={this.props.sortField} rowGroupMode={this.props.rowGroupMode} groupRowSpan={groupRowSpan}
onDragStart={(e) => this.onRowDragStart(e, i)} onDragEnd={this.onRowDragEnd} onDragOver={(e) => this.onRowDragOver(e, i)} onDragLeave={this.onRowDragLeave}
onDrop={this.onRowDrop}>{this.props.children}</BodyRow>
onDrop={this.onRowDrop} virtualRowHeight={this.props.virtualRowHeight}>{this.props.children}</BodyRow>

rows.push(bodyRow);

Expand Down
11 changes: 10 additions & 1 deletion src/showcase/datatable/DataTableDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,10 @@ export class DataTableRowGroupDemo extends Component {
<p>When using frozen columns with column grouping, use <i>frozenHeaderColumnGroup</i> and <i>frozenFooterColumnGroup</i> properties along with
<i>headerColumnGroup</i> and <i>footerColumnGroup</i>.</p>

<p>Virtual scrolling is enabled using <i>virtualScroll</i>, <i>onVirtualScroll</i> properties combined with lazy loading so that data is loaded on the fly during scrolling. View the <Link to="/datatable/scroll">scrolling demo</Link> for a sample implementation.</p>
<p>Virtual scrolling is enabled using <i>virtualScroll</i> and <i>onVirtualScroll</i> properties combined with lazy loading so that data is loaded on the fly during scrolling.
For smooth scrolling twice the amount of rows property is loaded on a lazy load event. In addition, to avoid performance problems row height is not calculated automatically and
should be provided using <i>virtualRowHeight</i> property which defaults to 28px. View the <Link to="/datatable/scroll">scrolling demo</Link> for a sample implementation.</p>

<CodeHighlight className="language-jsx">
{`
<DataTable value={this.state.lazyCars} scrollable={true} scrollHeight="200px" virtualScroll={true}
Expand Down Expand Up @@ -1844,6 +1847,12 @@ export class DataTableLazyDemo extends Component {
<td>250</td>
<td>Delay in virtual scroll before doing a call to lazy load.</td>
</tr>
<tr>
<td>virtualRowHeight</td>
<td>number</td>
<td>28</td>
<td>Height of a row to use in calculations of virtual scrolling.</td>
</tr>
<tr>
<td>frozenWidth</td>
<td>string</td>
Expand Down
4 changes: 2 additions & 2 deletions src/showcase/datatable/DataTableScrollDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class DataTableScrollDemo extends Component {
<Column field="color" header="Color" />
</DataTable>

<DataTable header="VirtualScroll with Lazy Loading" value={this.state.lazyCars} scrollable={true} scrollHeight="200px" virtualScroll={true}
<DataTable header="VirtualScroll with Lazy Loading" value={this.state.lazyCars} scrollable={true} scrollHeight="200px" virtualScroll={true} virtualRowHeight={30}
rows={10} totalRecords={this.state.lazyTotalRecords} lazy={true} onVirtualScroll={this.onVirtualScroll} loading={this.state.loading} style={{marginTop:'30px'}}>
<Column field="vin" header="Vin" />
<Column field="year" header="Year" />
Expand Down Expand Up @@ -295,7 +295,7 @@ export class DataTableScrollDemo extends Component {
<Column field="color" header="Color" />
</DataTable>
<DataTable header="VirtualScroll with Lazy Loading" value={this.state.lazyCars} scrollable={true} scrollHeight="200px" virtualScroll={true}
<DataTable header="VirtualScroll with Lazy Loading" value={this.state.lazyCars} scrollable={true} scrollHeight="200px" virtualScroll={true} virtualRowHeight={30}
rows={10} totalRecords={this.state.lazyTotalRecords} lazy={true} onVirtualScroll={this.onVirtualScroll} loading={this.state.loading} style={{marginTop:'30px'}}>
<Column field="vin" header="Vin" />
<Column field="year" header="Year" />
Expand Down

0 comments on commit 76f9137

Please sign in to comment.