Dynamic.js
5.62 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
import React from 'react';
import {
Breadcrumb,
BreadcrumbItem,
Progress,
Dropdown,
DropdownMenu,
DropdownToggle,
DropdownItem,
} from 'reactstrap';
import {
BootstrapTable,
TableHeaderColumn,
} from 'react-bootstrap-table';
import ReactTable from 'react-table';
import { reactTableData, reactBootstrapTableData } from './data';
import Widget from '../../../../components/Widget';
import s from './Dynamic.modules.scss';
class Dynamic extends React.Component {
constructor(props) {
super(props);
this.state = {
reactTable: reactTableData(),
reactBootstrapTable: reactBootstrapTableData(),
};
}
renderSizePerPageDropDown = (props) => {
const limits = [];
props.sizePerPageList.forEach((limit) => {
limits.push(<DropdownItem key={limit} onClick={() => props.changeSizePerPage(limit)}>{ limit }</DropdownItem>);
});
return (
<Dropdown isOpen={props.open} toggle={props.toggleDropDown}>
<DropdownToggle color="default" caret>
{ props.currSizePerPage }
</DropdownToggle>
<DropdownMenu>
{ limits }
</DropdownMenu>
</Dropdown>
);
};
render() {
const options = {
sizePerPage: 10,
paginationSize: 3,
sizePerPageDropDown: this.renderSizePerPageDropDown,
};
function infoFormatter(cell) {
return (
<div>
<small>
Type: <span className="fw-semi-bold">{cell.type}</span>
</small>
<br />
<small>
Dimensions: <span className="fw-semi-bold">{cell.dimensions}</span>
</small>
</div>
);
}
function descriptionFormatter(cell) {
return (
<button className="btn-link">
{cell}
</button>
);
}
function progressFormatter(cell) {
return (
<Progress style={{ height: '15px' }} color={cell.type} value={cell.progress} />
);
}
function progressSortFunc(a, b, order) {
if (order === 'asc') {
return a.status.progress - b.status.progress;
}
return b.status.progress - a.status.progress;
}
function dateSortFunc(a, b, order) {
if (order === 'asc') {
return new Date(a.date).getTime() - new Date(b.date).getTime();
}
return new Date(b.date).getTime() - new Date(a.date).getTime();
}
return (
<div>
<Breadcrumb>
<BreadcrumbItem>YOU ARE HERE</BreadcrumbItem>
<BreadcrumbItem active>Tables Dynamic</BreadcrumbItem>
</Breadcrumb>
<h2 className="page-title">Tables - <span className="fw-semi-bold">Dynamic</span></h2>
<Widget title={<h4>The <span className="fw-semi-bold">React</span> Way</h4>} collapse close>
<p>
Fully customizable Table. Built with <a href="https://allenfang.github.io/react-bootstrap-table/" target="_blank" rel="noopener noreferrer">react-bootstrap-table</a>
</p>
<BootstrapTable data={this.state.reactBootstrapTable} version="4" pagination options={options} search tableContainerClass={`table-striped table-hover ${s.bootstrapTable}`}>
<TableHeaderColumn className="width-50" columnClassName="width-50" dataField="id" isKey>
<span className="fs-sm">ID</span>
</TableHeaderColumn>
<TableHeaderColumn dataField="name" dataSort>
<span className="fs-sm">Name</span>
</TableHeaderColumn>
<TableHeaderColumn className="d-none d-md-table-cell" columnClassName="d-none d-md-table-cell" dataField="info" dataFormat={infoFormatter}>
<span className="fs-sm">Info</span>
</TableHeaderColumn>
<TableHeaderColumn className="d-none d-md-table-cell" columnClassName="d-none d-md-table-cell" dataField="description" dataFormat={descriptionFormatter}>
<span className="fs-sm">Description</span>
</TableHeaderColumn>
<TableHeaderColumn className="d-none d-md-table-cell" columnClassName="d-none d-md-table-cell" dataField="date" dataSort sortFunc={dateSortFunc}>
<span className="fs-sm">Date</span>
</TableHeaderColumn>
<TableHeaderColumn className="width-150" columnClassName="width-150" dataField="status" dataSort dataFormat={progressFormatter} sortFunc={progressSortFunc}>
<span className="fs-sm">Status</span>
</TableHeaderColumn>
</BootstrapTable>
</Widget>
<Widget title={<h4>React <span className="fw-semi-bold">Table</span></h4>} collapse close>
<p>
Simple table extension with sorting, filtering and pagination for React apps. Built with <a href="https://react-table.js.org/" target="_blank" rel="noopener noreferrer">react-table</a>
</p>
<ReactTable
data={this.state.reactTable}
filterable
columns={[
{
Header: 'NAME',
accessor: 'name',
},
{
Header: 'POSITION',
accessor: 'position',
},
{
Header: 'OFFICE',
accessor: 'office',
},
{
Header: 'EXT',
accessor: 'ext',
},
{
Header: 'START DATE',
accessor: 'startDate',
},
{
Header: 'SALARY',
accessor: 'salary',
},
]}
defaultPageSize={10}
className="-striped -highlight"
/>
</Widget>
</div>
);
}
}
export default Dynamic;