fixed-data-table-one.com
Version:
A React table component designed to allow presenting thousands of rows of data.
87 lines (78 loc) • 2.23 kB
JavaScript
/**
* Copyright Schrodinger, LLC
*/
;
const FakeObjectDataListStore = require('./helpers/FakeObjectDataListStore');
const { TextCell } = require('./helpers/cells');
const { Table, Column, Cell } = require('fixed-data-table-2');
const React = require('react');
class ResizeExample extends React.Component {
constructor(props) {
super(props);
this.state = {
dataList: new FakeObjectDataListStore(1000000),
columnWidths: {
firstName: 240,
lastName: 150,
sentence: 140,
companyName: 60,
},
};
this._onColumnResizeEndCallback = this._onColumnResizeEndCallback.bind(this);
}
_onColumnResizeEndCallback(newColumnWidth, columnKey) {
this.setState(({columnWidths}) => ({
columnWidths: {
...columnWidths,
[columnKey]: newColumnWidth,
}
}));
}
render() {
var {dataList, columnWidths} = this.state;
return (
<Table
rowHeight={30}
headerHeight={50}
rowsCount={dataList.getSize()}
onColumnResizeEndCallback={this._onColumnResizeEndCallback}
isColumnResizing={false}
width={1000}
height={500}
{...this.props}>
<Column
columnKey="firstName"
header={<Cell>First Name</Cell>}
cell={<TextCell data={dataList} />}
fixed={true}
width={columnWidths.firstName}
isResizable={true}
/>
<Column
columnKey="lastName"
header={<Cell>Last Name (min/max constrained)</Cell>}
cell={<TextCell data={dataList} />}
width={columnWidths.lastName}
isResizable={true}
minWidth={70}
maxWidth={170}
/>
<Column
columnKey="companyName"
header={<Cell>Company</Cell>}
cell={<TextCell data={dataList} />}
width={columnWidths.companyName}
isResizable={true}
/>
<Column
columnKey="sentence"
header={<Cell>Sentence</Cell>}
cell={<TextCell data={dataList} />}
width={columnWidths.sentence}
isResizable={true}
/>
</Table>
);
}
}
module.exports = ResizeExample;