This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.jsx
95 lines (77 loc) · 2.26 KB
/
index.jsx
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
'use strict';
require('./index.styl')
var sorty = require('sorty')
var React = require('react')
var ReactDOM = require('react-dom')
var DataGrid = require('./src')
var faker = window.faker = require('faker');
var preventDefault = require('./src/utils/preventDefault')
console.log(React.version,' react version');
var gen = (function(){
var cache = {}
return function(len){
if (cache[len]){
// return cache[len]
}
var arr = []
for (var i = 0; i < len; i++){
arr.push({
id : i + 1,
grade : Math.round(Math.random() * 10),
email : faker.internet.email(),
firstName: faker.name.firstName(),
lastName : faker.name.lastName(),
birthDate: faker.date.past(),
country : faker.address.country(),
city : faker.address.city()
})
}
cache[len] = arr
return arr
}
})()
var RELOAD = true
var columns = [
{ name: 'index', title: '#', width: 50},
{ name: 'country', width: 200},
{ name: 'city', width: 150 },
{ name: 'firstName' },
{ name: 'lastName' },
{ name: 'email', width: 200 }
]
var ROW_HEIGHT = 31
var LEN = 2000
var SORT_INFO = [{name: 'country', dir: 'asc'}]//[ { name: 'id', dir: 'asc'} ]
var sort = sorty(SORT_INFO)
var data = gen(LEN);
class App extends React.Component {
constructor(props, context) {
super(props, context);
this.handleSortChange = this.handleSortChange.bind(this);
this.onColumnResize = this.onColumnResize.bind(this);
}
onColumnResize(firstCol, firstSize, secondCol, secondSize) {
firstCol.width = firstSize
this.setState({})
}
render() {
return <DataGrid
ref="dataGrid"
idProperty='id'
dataSource={data}
sortInfo={SORT_INFO}
onSortChange={this.handleSortChange}
columns={columns}
style={{height: 400}}
onColumnResize={this.onColumnResize}
/>
}
handleSortChange(sortInfo) {
SORT_INFO = sortInfo
data = sort(data)
this.setState({})
}
}
ReactDOM.render((
<App />
), document.getElementById('content'))