-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathUserList.js
More file actions
184 lines (173 loc) · 5.55 KB
/
UserList.js
File metadata and controls
184 lines (173 loc) · 5.55 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, { Component, Fragment } from 'react';
// import ReactDatatable from '../../lib/index.js';
import ReactDatatable from '../../src/index.js';
import users from '../data/data.json';
class UserList extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
users: []
};
this.deleteUser = this.deleteUser.bind(this);
this.columns = [
{
key: "name",
text: "Name",
className: "name",
TrOnlyClassName:"aClass",
align: "left",
sortable: true,
},
{
key: "address",
text: "Address",
className: "address",
align: "left",
sortable: true
},
{
key: "postcode",
text: "Postcode",
className: "postcode",
sortable: true
},
{
key: "rating",
text: "Rating",
className: "rating",
align: "left",
sortable: true,
cell: record => {
return <span>{record.rating} {record.type_of_food}</span>
}
},
{
key: "type_of_food",
text: "Type of Food",
className: "type_of_food",
sortable: true,
align: "left"
},
{
key: "action",
text: "Action",
className: "action",
width: 100,
align: "left",
sortable: false,
cell: record => {
return (
<Fragment>
<button
className="btn btn-primary btn-sm"
onClick={() => this.editUser(record)}
style={{marginRight: '5px'}}>
<i className="glyphicon glyphicon-edit fa fa-edit"></i>
</button>
<button className="btn btn-danger btn-sm" onClick={() => this.deleteUser(record)}>
<i className="glyphicon glyphicon-trash fa fa-trash"></i>
</button>
</Fragment>
);
}
}
];
this.config = {
key_column: '_id',
page_size: 10,
length_menu: [ 10, 20, 50 ],
filename: "Users",
no_data_text: 'No data available!',
button: {
excel: true,
print: true,
csv: true,
extra: false,
},
language: {
length_menu: "Show _MENU_ result per page",
filter: "Filter in records...",
info: "Showing _START_ to _END_ of _TOTAL_ records",
pagination: {
first: "First",
previous: <span>◄</span>,
next: <span>►</span>,
last: "Last"
}
},
pagination: "advance", //advance
show_length_menu: true,
show_filter: true,
show_pagination: true,
show_info: true,
};
this.extraButtons =[
{
className:"btn btn-primary buttons-pdf",
title:"Export TEst",
children:[
<span>
<i className="glyphicon glyphicon-print fa fa-print" aria-hidden="true"></i>
</span>
],
onClick:(event)=>{
console.log(event);
},
},
{
className:"btn btn-primary buttons-pdf",
title:"Export TEst",
children:[
<span>
<i className="glyphicon glyphicon-print fa fa-print" aria-hidden="true"></i>
</span>
],
onClick:(event)=>{
console.log(event);
},
onDoubleClick:(event)=>{
console.log("doubleClick")
}
},
]
}
componentDidMount () {
setTimeout(() => {
this.setState({
loading: false,
users: users
})
}, 3000);
}
editUser(user) {
console.log("Edit User", user);
}
deleteUser(user) {
console.log("Delete User", user);
}
pageChange(pageData) {
console.log("OnPageChange", pageData);
}
customSort(column, records, sortOrder) {
console.log("column: %s, records: %O, sortOrder: %s", column, records, sortOrder);
return records;
}
render() {
return (
<div>
<ReactDatatable
className="table table-bordered table-striped custom-class"
config={this.config}
records={this.state.users}
columns={this.columns}
onPageChange={this.pageChange.bind(this)}
extraButtons={this.extraButtons}
loading={this.state.loading}
onSort={this.customSort}
/>
</div>
)
}
}
export default UserList;