1
1
1
1
xxxxxxxxxx
1
import React, { Component } from 'react';
2
import { MDBDataTable, MDBInput } from 'mdbreact';
3
4
var arrayClientData = [];
5
6
class App extends Component {
7
state = {
8
checked: []
9
};
10
11
constructor(props) {
12
super(props);
13
this.fetchClientData();
14
}
15
16
toggleCheck = e => {
17
let checkedArr = this.state.checked;
18
checkedArr.filter(name => name === e.target.id)[0]
19
? checkedArr = checkedArr.filter(name => name !== e.target.id)
20
: checkedArr.push(e.target.id);
21
this.setState({ checked: checkedArr })
22
23
};
24
25
isChecked = id => this.state.checked.filter(name => name === id)[0] ? true : false
26
27
fetchClientData() {
28
29
const property = this.props;
30
const contextNew = this;
31
fetch("http://localhost:5000/users/CustomersDetails", {
32
method: "GET",
33
headers: {
34
"Content-Type": "application/json"
35
},
36
}).then(function (response) {
37
return response.json();
38
39
})
40
.then(function (data) {
41
const myObjStr = JSON.stringify(data);
42
43
const success = JSON.parse(myObjStr).success;
44
45
const status = JSON.parse(myObjStr).status;
46
47
const message = JSON.parse(myObjStr).message;
48
49
if (success === true && status === 'CustomersList') {
50
const dataCustomer = JSON.parse(myObjStr).customerData;
51
const customerListData = JSON.stringify(dataCustomer);
52
const jsonArray = JSON.parse(customerListData);
53
54
arrayClientData = [];
55
for (var i = 0; i < jsonArray.length; i++) {
56
57
const j = {
58
check: <MDBInput label=' ' type='checkbox' id={'checkbox' + i} onClick={contextNew.toggleCheck}
59
checked={contextNew.isChecked('checkbox' + i)} />,
60
name: 'Tiger Nixon' + i,
61
position: 'System Architect' + i,
62
office: 'Edinburgh' + i,
63
age: '61',
64
date: '2011/04/25',
65
salary: '$320'
66
};
67
68
arrayClientData[i] = j;
69
70
}
71
72
contextNew.setState(contextNew.state);
73
74
}
75
else if (success === true && status === 'NoCustomers') {
76
77
}
78
else {
79
80
}
81
82
83
}).catch(err => {
84
console.log("clients", "catch=>" + err);
85
});
86
}
87
88
render() {
89
const data = {
90
columns: [
91
{
92
label: 'Check',
93
field: 'check',
94
sort: 'disabled',
95
width: 20
96
},
97
{
98
label: 'Name',
99
field: 'name',
100
sort: 'asc',
101
width: 150
102
},
103
{
104
label: 'Position',
105
field: 'position',
106
sort: 'asc',
107
width: 270
108
},
109
{
110
label: 'Office',
111
field: 'office',
112
sort: 'asc',
113
width: 200
114
},
115
{
116
label: 'Age',
117
field: 'age',
118
sort: 'asc',
119
width: 100
120
},
121
{
122
label: 'Start date',
123
field: 'date',
124
sort: 'asc',
125
width: 150
126
},
127
{
128
label: 'Salary',
129
field: 'salary',
130
sort: 'asc',
131
width: 100
132
}
133
],
134
rows: arrayClientData
135
};
136
137
return <MDBDataTable striped bordered hover data={data} />;
138
}
139
}
140
141
export default App;
142
143
144
Console errors: 0