-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample_react_table.txt
65 lines (53 loc) · 1.67 KB
/
sample_react_table.txt
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
import React, { Component } from './types/react';
declare var ReactDOM;
//state class
class MyReactState {
title = 'React Table';
numRows = 1;
}
//main component
class MyReactApp extends Component<{}, MyReactState>{
constructor(props) {
super(props);
this.state = new MyReactState();
}
buttonClicked() {
this.setState({ numRows: this.state.numRows + 1 });
}
render() {
let rows = [];
for (let i = 0; i < this.state.numRows; i++)
rows.push(<tr key={i}><td>Maddy</td><td>{i}</td></tr>);
let myTable = <table className="table" style={{ marginTop: '20px' }}>
<tbody>
<tr>
<th>Name</th>
<th>RowNum</th>
</tr>
{rows}
</tbody>
</table>;
return (
<div className="container">
<h1>{this.state.title}</h1>
<br></br>
<MyButton buttonName="Add Row" onButtonClicked={this.buttonClicked.bind(this)}></MyButton>
{ myTable}
</div>
);
}
}
//button component
class MyButton extends Component<{buttonName: string;onButtonClicked: (event: any) => void}, {}> {
buttonClicked() {
this.props.onButtonClicked('');
}
render() {
return (
<div>
<button type="button" onClick={this.buttonClicked.bind(this)} className="btn btn-primary">{this.props.buttonName}</button>
</div>
);
}
}
ReactDOM.render(React.createElement(MyReactApp), document.getElementById('divOutput'));