質問編集履歴
1
質問の内容を変更しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,24 +1,414 @@
|
|
1
|
-
現在、axiosを使ってJSONデータを取得して、その内容を一覧でテーブルで表示することまではできました。
|
2
|
-
|
3
|
-
|
1
|
+
現在、Material UIライブラリのドキュメントに載っているページネーションを使ったテーブルを作成したいと考えています。
|
4
|
-
|
5
|
-
|
2
|
+
|
6
|
-
|
7
|
-
やり方がわかる方がいれば、ご教示お願いいたします。
|
8
|
-
|
9
|
-
|
3
|
+
具体的には、https://material-ui.com/components/tables/ に載っているCustom pagination actionsを実装したいです。
|
4
|
+
|
10
|
-
|
5
|
+
下記の画像のようなものです。
|
6
|
+
|
7
|
+
![イメージ説明](cfcbc76d34e61dc21be10696813d2bd3.png)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
PagenationTableComponent.jsにCheckList.jsにあるようにaxiosで渡ってきたjsonデータを表示したいのですが、下記のようなエラーが出てしまいます。
|
12
|
+
|
13
|
+
このrows.sliceが機能していないというのがどうすれば修正できるかご教示お願いします。
|
14
|
+
|
15
|
+
jsonデータは以下のようなものです。
|
16
|
+
|
17
|
+
[{"listNo":1,
|
18
|
+
|
19
|
+
"saiyouDate":"2008-10-06 ",
|
20
|
+
|
21
|
+
"softwareName":"Symantec Endpoint Protection",
|
22
|
+
|
23
|
+
"version":"‐",
|
24
|
+
|
25
|
+
"shubetu":"有償",
|
26
|
+
|
27
|
+
"licenseManage":"○",
|
28
|
+
|
29
|
+
"youto":"ウイルス対策",
|
30
|
+
|
31
|
+
"bikou":"使用する場合はシステム管理まで連絡が必要",
|
32
|
+
|
33
|
+
"authorizer":"山田",
|
34
|
+
|
35
|
+
"approvalDate":"2008-10-06 ",
|
36
|
+
|
37
|
+
"url":"https://jp.broadcom.com/products/cyber-security/endpoint/end-user"}]
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
TypeError: rows.slice is not a function
|
42
|
+
|
11
|
-
|
43
|
+
CustomPaginationActionsTable
|
44
|
+
|
12
|
-
|
45
|
+
C:/workspace/spring-backend-3/frontend/src/component/PagenationTableComponent.js:117
|
46
|
+
|
47
|
+
114 | return (
|
48
|
+
|
49
|
+
115 |
|
50
|
+
|
51
|
+
116 |
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
117 |
|
56
|
+
|
57
|
+
| ^ 118 | {(rowsPerPage > 0
|
58
|
+
|
59
|
+
119 | ? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
60
|
+
|
61
|
+
120 | : rows
|
62
|
+
|
13
|
-
|
63
|
+
View compiled
|
64
|
+
|
65
|
+
▶ 17 stack frames were collapsed.
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
PagenationTableComponent.js
|
14
70
|
|
15
71
|
```js
|
16
72
|
|
73
|
+
import React from 'react';
|
74
|
+
|
75
|
+
import PropTypes from 'prop-types';
|
76
|
+
|
77
|
+
import { makeStyles, useTheme } from '@material-ui/core/styles';
|
78
|
+
|
79
|
+
import Table from '@material-ui/core/Table';
|
80
|
+
|
81
|
+
import TableBody from '@material-ui/core/TableBody';
|
82
|
+
|
83
|
+
import TableCell from '@material-ui/core/TableCell';
|
84
|
+
|
85
|
+
import TableContainer from '@material-ui/core/TableContainer';
|
86
|
+
|
87
|
+
import TableFooter from '@material-ui/core/TableFooter';
|
88
|
+
|
89
|
+
import TablePagination from '@material-ui/core/TablePagination';
|
90
|
+
|
91
|
+
import TableRow from '@material-ui/core/TableRow';
|
92
|
+
|
93
|
+
import Paper from '@material-ui/core/Paper';
|
94
|
+
|
95
|
+
import IconButton from '@material-ui/core/IconButton';
|
96
|
+
|
97
|
+
import FirstPageIcon from '@material-ui/icons/FirstPage';
|
98
|
+
|
99
|
+
import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft';
|
100
|
+
|
101
|
+
import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';
|
102
|
+
|
103
|
+
import LastPageIcon from '@material-ui/icons/LastPage';
|
104
|
+
|
105
|
+
import CheckListService from '../services/CheckList';
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
const useStyles1 = makeStyles((theme) => ({
|
110
|
+
|
111
|
+
root: {
|
112
|
+
|
113
|
+
flexShrink: 0,
|
114
|
+
|
115
|
+
marginLeft: theme.spacing(2.5),
|
116
|
+
|
117
|
+
},
|
118
|
+
|
119
|
+
}));
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
function TablePaginationActions(props) {
|
124
|
+
|
125
|
+
const classes = useStyles1();
|
126
|
+
|
127
|
+
const theme = useTheme();
|
128
|
+
|
129
|
+
const { count, page, rowsPerPage, onChangePage } = props;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
const handleFirstPageButtonClick = (event) => {
|
134
|
+
|
135
|
+
onChangePage(event, 0);
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
const handleBackButtonClick = (event) => {
|
142
|
+
|
143
|
+
onChangePage(event, page - 1);
|
144
|
+
|
145
|
+
};
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
const handleNextButtonClick = (event) => {
|
150
|
+
|
151
|
+
onChangePage(event, page + 1);
|
152
|
+
|
153
|
+
};
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
const handleLastPageButtonClick = (event) => {
|
158
|
+
|
159
|
+
onChangePage(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
|
160
|
+
|
161
|
+
};
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
return (
|
166
|
+
|
167
|
+
<div className={classes.root}>
|
168
|
+
|
169
|
+
<IconButton
|
170
|
+
|
171
|
+
onClick={handleFirstPageButtonClick}
|
172
|
+
|
173
|
+
disabled={page === 0}
|
174
|
+
|
175
|
+
aria-label="first page"
|
176
|
+
|
177
|
+
>
|
178
|
+
|
179
|
+
{theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
|
180
|
+
|
181
|
+
</IconButton>
|
182
|
+
|
183
|
+
<IconButton onClick={handleBackButtonClick} disabled={page === 0} aria-label="previous page">
|
184
|
+
|
185
|
+
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
|
186
|
+
|
187
|
+
</IconButton>
|
188
|
+
|
189
|
+
<IconButton
|
190
|
+
|
191
|
+
onClick={handleNextButtonClick}
|
192
|
+
|
193
|
+
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
|
194
|
+
|
195
|
+
aria-label="next page"
|
196
|
+
|
197
|
+
>
|
198
|
+
|
199
|
+
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
|
200
|
+
|
201
|
+
</IconButton>
|
202
|
+
|
203
|
+
<IconButton
|
204
|
+
|
205
|
+
onClick={handleLastPageButtonClick}
|
206
|
+
|
207
|
+
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
|
208
|
+
|
209
|
+
aria-label="last page"
|
210
|
+
|
211
|
+
>
|
212
|
+
|
213
|
+
{theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
|
214
|
+
|
215
|
+
</IconButton>
|
216
|
+
|
217
|
+
</div>
|
218
|
+
|
219
|
+
);
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
TablePaginationActions.propTypes = {
|
226
|
+
|
227
|
+
count: PropTypes.number.isRequired,
|
228
|
+
|
229
|
+
onChangePage: PropTypes.func.isRequired,
|
230
|
+
|
231
|
+
page: PropTypes.number.isRequired,
|
232
|
+
|
233
|
+
rowsPerPage: PropTypes.number.isRequired,
|
234
|
+
|
235
|
+
};
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
let rows = [];
|
240
|
+
|
241
|
+
rows = CheckListService.getList().then((response) => {
|
242
|
+
|
243
|
+
return response.data
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
});
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
const useStyles2 = makeStyles({
|
256
|
+
|
257
|
+
table: {
|
258
|
+
|
259
|
+
minWidth: 500,
|
260
|
+
|
261
|
+
},
|
262
|
+
|
263
|
+
});
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
export default function CustomPaginationActionsTable() {
|
268
|
+
|
269
|
+
const classes = useStyles2();
|
270
|
+
|
271
|
+
const [page, setPage] = React.useState(0);
|
272
|
+
|
273
|
+
const [rowsPerPage, setRowsPerPage] = React.useState(5);
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
const emptyRows = rowsPerPage - Math.min(rowsPerPage, rows.length - page * rowsPerPage);
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
const handleChangePage = (event, newPage) => {
|
282
|
+
|
283
|
+
setPage(newPage);
|
284
|
+
|
285
|
+
};
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
const handleChangeRowsPerPage = (event) => {
|
290
|
+
|
291
|
+
setRowsPerPage(parseInt(event.target.value, 10));
|
292
|
+
|
293
|
+
setPage(0);
|
294
|
+
|
295
|
+
};
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
return (
|
300
|
+
|
301
|
+
<TableContainer component={Paper}>
|
302
|
+
|
303
|
+
<Table className={classes.table} aria-label="custom pagination table">
|
304
|
+
|
305
|
+
<TableBody>
|
306
|
+
|
307
|
+
{(rowsPerPage > 0
|
308
|
+
|
309
|
+
? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
310
|
+
|
311
|
+
: rows
|
312
|
+
|
313
|
+
).map((row) => (
|
314
|
+
|
315
|
+
<TableRow key={row.listNo}>
|
316
|
+
|
317
|
+
<TableCell component="th" scope="row">
|
318
|
+
|
319
|
+
{row.listNo}
|
320
|
+
|
321
|
+
</TableCell>
|
322
|
+
|
323
|
+
<TableCell style={{ width: 160 }} align="right">
|
324
|
+
|
325
|
+
{row.saiyouDate}
|
326
|
+
|
327
|
+
</TableCell>
|
328
|
+
|
329
|
+
<TableCell style={{ width: 160 }} align="right">
|
330
|
+
|
331
|
+
{row.softwareName}
|
332
|
+
|
333
|
+
</TableCell>
|
334
|
+
|
335
|
+
</TableRow>
|
336
|
+
|
337
|
+
))}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
{emptyRows > 0 && (
|
342
|
+
|
343
|
+
<TableRow style={{ height: 53 * emptyRows }}>
|
344
|
+
|
345
|
+
<TableCell colSpan={6} />
|
346
|
+
|
347
|
+
</TableRow>
|
348
|
+
|
349
|
+
)}
|
350
|
+
|
351
|
+
</TableBody>
|
352
|
+
|
353
|
+
<TableFooter>
|
354
|
+
|
355
|
+
<TableRow>
|
356
|
+
|
357
|
+
<TablePagination
|
358
|
+
|
359
|
+
rowsPerPageOptions={[5, 10, 25, { label: 'All', value: -1 }]}
|
360
|
+
|
361
|
+
colSpan={3}
|
362
|
+
|
363
|
+
count={rows.length}
|
364
|
+
|
365
|
+
rowsPerPage={rowsPerPage}
|
366
|
+
|
367
|
+
page={page}
|
368
|
+
|
369
|
+
SelectProps={{
|
370
|
+
|
371
|
+
inputProps: { 'aria-label': 'rows per page' },
|
372
|
+
|
373
|
+
native: true,
|
374
|
+
|
375
|
+
}}
|
376
|
+
|
377
|
+
onChangePage={handleChangePage}
|
378
|
+
|
379
|
+
onChangeRowsPerPage={handleChangeRowsPerPage}
|
380
|
+
|
381
|
+
ActionsComponent={TablePaginationActions}
|
382
|
+
|
383
|
+
/>
|
384
|
+
|
385
|
+
</TableRow>
|
386
|
+
|
387
|
+
</TableFooter>
|
388
|
+
|
389
|
+
</Table>
|
390
|
+
|
391
|
+
</TableContainer>
|
392
|
+
|
393
|
+
);
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
```
|
402
|
+
|
403
|
+
CheckList.js
|
404
|
+
|
405
|
+
```js
|
406
|
+
|
17
407
|
import axios from 'axios'
|
18
408
|
|
19
409
|
|
20
410
|
|
21
|
-
const CHECKLIST_REST_API_URL = 'http://localhost:8080/api/
|
411
|
+
const CHECKLIST_REST_API_URL = 'http://localhost:8080/api/users';
|
22
412
|
|
23
413
|
|
24
414
|
|
@@ -41,193 +431,3 @@
|
|
41
431
|
export default new CheckListService();
|
42
432
|
|
43
433
|
```
|
44
|
-
|
45
|
-
```js
|
46
|
-
|
47
|
-
import React from 'react';
|
48
|
-
|
49
|
-
import CheckListService from '../services/CheckList';
|
50
|
-
|
51
|
-
import Table from '@material-ui/core/Table';
|
52
|
-
|
53
|
-
import TableBody from '@material-ui/core/TableBody';
|
54
|
-
|
55
|
-
import TableCell from '@material-ui/core/TableCell';
|
56
|
-
|
57
|
-
import TableContainer from '@material-ui/core/TableContainer';
|
58
|
-
|
59
|
-
import TableHead from '@material-ui/core/TableHead';
|
60
|
-
|
61
|
-
import TableRow from '@material-ui/core/TableRow';
|
62
|
-
|
63
|
-
import Paper from '@material-ui/core/Paper';
|
64
|
-
|
65
|
-
import CssBaseline from '@material-ui/core/CssBaseline';
|
66
|
-
|
67
|
-
import Container from '@material-ui/core/Container';
|
68
|
-
|
69
|
-
import { makeStyles } from '@material-ui/core/styles';
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
class CheckListComponent extends React.Component {
|
74
|
-
|
75
|
-
constructor(props) {
|
76
|
-
|
77
|
-
super(props)
|
78
|
-
|
79
|
-
this.state = {
|
80
|
-
|
81
|
-
list: []
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
componentDidMount() {
|
90
|
-
|
91
|
-
CheckListService.getList().then((response) => {
|
92
|
-
|
93
|
-
this.setState({ list: response.data })
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
});
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
render() {
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
return (
|
120
|
-
|
121
|
-
<React.Fragment>
|
122
|
-
|
123
|
-
<CssBaseline />
|
124
|
-
|
125
|
-
<Container maxWidth="lg" className="mt-5">
|
126
|
-
|
127
|
-
<h1>使用許可ソフトウェアリスト</h1>
|
128
|
-
|
129
|
-
<TableContainer component={Paper}>
|
130
|
-
|
131
|
-
<Table className="table text-nowrap" size="small" aria-label="a dense table">
|
132
|
-
|
133
|
-
<TableHead>
|
134
|
-
|
135
|
-
<TableRow>
|
136
|
-
|
137
|
-
<TableCell>リスト番号</TableCell>
|
138
|
-
|
139
|
-
<TableCell align="right">採用日</TableCell>
|
140
|
-
|
141
|
-
<TableCell align="right">ソフトウェア名</TableCell>
|
142
|
-
|
143
|
-
<TableCell align="right">バージョン</TableCell>
|
144
|
-
|
145
|
-
<TableCell align="right">種別</TableCell>
|
146
|
-
|
147
|
-
<TableCell align="right">ライセンス</TableCell>
|
148
|
-
|
149
|
-
<TableCell align="right">用途</TableCell>
|
150
|
-
|
151
|
-
<TableCell align="right">備考</TableCell>
|
152
|
-
|
153
|
-
<TableCell align="right">承認者</TableCell>
|
154
|
-
|
155
|
-
<TableCell align="right">承認日</TableCell>
|
156
|
-
|
157
|
-
<TableCell align="right">URL</TableCell>
|
158
|
-
|
159
|
-
</TableRow>
|
160
|
-
|
161
|
-
</TableHead>
|
162
|
-
|
163
|
-
<TableBody>
|
164
|
-
|
165
|
-
{this.state.list.map((
|
166
|
-
|
167
|
-
list => {
|
168
|
-
|
169
|
-
return <TableRow key={list.listNo}>
|
170
|
-
|
171
|
-
<TableCell component="th" scope="row">
|
172
|
-
|
173
|
-
{list.listNo}
|
174
|
-
|
175
|
-
</TableCell>
|
176
|
-
|
177
|
-
<TableCell align="right">{list.saiyouDate}</TableCell>
|
178
|
-
|
179
|
-
<TableCell align="right">{list.softwareName}</TableCell>
|
180
|
-
|
181
|
-
<TableCell align="right">{list.version}</TableCell>
|
182
|
-
|
183
|
-
<TableCell align="right">{list.shubetu}</TableCell>
|
184
|
-
|
185
|
-
<TableCell align="right">{list.licenseManage}</TableCell>
|
186
|
-
|
187
|
-
<TableCell align="right">{list.youto}</TableCell>
|
188
|
-
|
189
|
-
<TableCell align="right">{list.bikou}</TableCell>
|
190
|
-
|
191
|
-
<TableCell align="right">{list.authorizer}</TableCell>
|
192
|
-
|
193
|
-
<TableCell align="right">{list.approvalDate}</TableCell>
|
194
|
-
|
195
|
-
<TableCell align="right">{list.url}</TableCell>
|
196
|
-
|
197
|
-
</TableRow>;
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
))}
|
202
|
-
|
203
|
-
</TableBody>
|
204
|
-
|
205
|
-
</Table>
|
206
|
-
|
207
|
-
</TableContainer>
|
208
|
-
|
209
|
-
</Container>
|
210
|
-
|
211
|
-
</React.Fragment>
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
)
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
export default CheckListComponent
|
232
|
-
|
233
|
-
```
|