-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
109 lines (99 loc) · 2.87 KB
/
index.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
109
import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
import '@progress/kendo-theme-default';
import {
Grid,
GridColumn as Column,
GridDetailRow,
} from '@progress/kendo-react-grid';
import { toODataString } from '@progress/kendo-data-query';
class DetailComponent extends GridDetailRow {
render() {
return (
<Grid data={this.props.dataItem.details}>
<Column field="Id" title="ID" width="120px" />
<Column field="Network" title="Network" />
<Column field="User" title="User" format="{0:c}" />
</Grid>
);
}
}
class App extends React.Component {
baseUrl = `http://degen-defi.com/odata/`;
init = { method: 'GET', accept: 'application/json', headers: {} };
constructor(props) {
super(props);
this.state = {
categories: [],
dataState: {},
};
this.expandChange = this.expandChange.bind(this);
this.dataStateChange = this.dataStateChange.bind(this);
}
expandChange(event) {
let dataItem = event.dataItem;
dataItem.expanded = !dataItem.expanded;
this.forceUpdate();
if (!dataItem.expanded) {
return;
}
fetch(this.baseUrl + `degenlog`, this.init)
.then((response) => response.json())
.then((json) => {
let data = this.state.categories.slice();
let index = data.findIndex((d) => d.CategoryID === dataItem.CategoryID);
data[index].details = json.value;
this.setState({ categories: data });
});
}
dataStateChange(event) {
this.setState({
dataState: event.data,
categories: this.state.categories,
});
fetch(this.baseUrl + `degenlog?` + toODataString(event.data), this.init)
.then((response) => response.json())
.then((json) =>
this.setState({
categories: json.value,
dataState: this.state.dataState,
})
);
}
componentDidMount() {
fetch(this.baseUrl + `degenlog`, this.init)
.then((response) => response.json())
.then((json) => this.setState({ categories: json.value }));
}
render() {
return (
<div>
<Grid
style={{ height: '550px' }}
data={this.state.categories}
detail={DetailComponent}
expandField="expanded"
expandChange={this.expandChange}
filterable={true}
sortable={true}
pageable={true}
dataStateChange={this.dataStateChange}
sort={this.state.dataState.sort}
filter={this.state.dataState.filter}
>
<Column
field="Id"
filter="numeric"
title="ID"
width="200px"
/>
<Column field="Network" width="200px" title="Network" />
<Column field="User" sortable={false} />
</Grid>
</div>
);
}
}
render(<App />, document.getElementById('root'));