-
Notifications
You must be signed in to change notification settings - Fork 782
/
select-validation-table.js
57 lines (49 loc) · 1.41 KB
/
select-validation-table.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
/* eslint max-len: 0 */
/* eslint no-alert: 0 */
/* eslint guard-for-in: 0 */
/* eslint no-console: 0 */
/* eslint no-unused-vars: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i++) {
const id = startId + i;
products.push({
id: id,
name: 'Item name ' + id,
price: 2100 + i
});
}
}
addProducts(5);
function onRowSelect(row, isSelected, e) {
if (isSelected && row.id >= 3) {
alert('The selection only work on key which less than 3');
return false;
}
}
function onSelectAll(isSelected, rows) {
if (isSelected) {
alert('The selection only work on key which less than 3');
return products.map(p => p.id).filter(id => id < 3);
}
}
const selectRowProp = {
mode: 'checkbox',
clickToSelect: true,
onSelect: onRowSelect,
onSelectAll: onSelectAll
};
export default class SelectValidationTable extends React.Component {
render() {
return (
<BootstrapTable data={ products } selectRow={ selectRowProp }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}