forked from schrodinger/fixed-data-table-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReorderExample.js
108 lines (95 loc) · 2.5 KB
/
ReorderExample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Copyright Schrodinger, LLC
*/
"use strict";
const FakeObjectDataListStore = require('./helpers/FakeObjectDataListStore');
const { TextCell } = require('./helpers/cells');
const { Table, Column, Cell } = require('fixed-data-table-2');
const React = require('react');
var columnTitles = {
'firstName': 'First Name',
'lastName': 'Last Name',
'sentence': 'Sentence',
'companyName': 'Company',
'city': 'City',
'street': 'Street',
'zipCode': 'Zip Code'
};
var columnWidths = {
firstName: 150,
lastName: 150,
sentence: 240,
companyName: 100,
city: 240,
street: 260,
zipCode: 240
};
var fixedColumns = [
'firstName',
'lastName'
];
class ReorderExample extends React.Component {
constructor(props) {
super(props);
this.state = {
dataList: new FakeObjectDataListStore(1000000),
columnOrder: [
'firstName',
'lastName',
'city',
'street',
'zipCode',
'sentence',
'companyName'
],
};
this._onColumnReorderEndCallback = this._onColumnReorderEndCallback.bind(this);
}
_onColumnReorderEndCallback(event) {
console.log(event);
var columnOrder = this.state.columnOrder.filter((columnKey) => {
return columnKey !== event.reorderColumn;
});
if (event.columnAfter) {
var index = columnOrder.indexOf(event.columnAfter);
columnOrder.splice(index, 0, event.reorderColumn);
} else {
if (fixedColumns.indexOf(event.reorderColumn) !== -1) {
columnOrder.splice(fixedColumns.length - 1, 0, event.reorderColumn)
} else {
columnOrder.push(event.reorderColumn);
}
}
this.setState({
columnOrder: columnOrder
});
}
render() {
var {dataList} = this.state;
return (
<Table
rowHeight={30}
headerHeight={50}
rowsCount={dataList.getSize()}
onColumnReorderEndCallback={this._onColumnReorderEndCallback}
isColumnReordering={false}
width={1000}
height={500}
{...this.props}>
{this.state.columnOrder.map(function (columnKey, i) {
return <Column
allowCellsRecycling={true}
columnKey={columnKey}
key={i}
isReorderable={true}
header={<Cell>{columnTitles[columnKey]}</Cell>}
cell={<TextCell data={dataList} />}
fixed={fixedColumns.indexOf(columnKey) !== -1}
width={columnWidths[columnKey]}
/>;
})}
</Table>
);
}
}
module.exports = ReorderExample;