Skip to content

Commit 3c24be5

Browse files
committed
select validation
1 parent 4666523 commit 3c24be5

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

examples/js/selection/demo.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DefaultSelectTable from './default-select-table';
77
import SelectBgColorTable from './select-bgcolor-table';
88
import SelectHookTable from './select-hook-table';
99
import HideSelectionColumnTable from './hide-selection-col-table';
10+
import SelectValidationTable from './select-validation-table';
1011
import RowClickTable from './row-click-table';
1112
import OnlySelectedTable from './only-show-selected-table';
1213
import ExternallyManagedSelection from './externally-managed-selection';
@@ -78,6 +79,16 @@ class Demo extends React.Component {
7879
</div>
7980
</div>
8081
</div>
82+
<div className='col-md-offset-1 col-md-8'>
83+
<div className='panel panel-default'>
84+
<div className='panel-heading'>Select Validation Example</div>
85+
<div className='panel-body'>
86+
<h5>Source in /examples/js/selection/row-click-table.js</h5>
87+
<h5>Only able to select the rows which key is less 3.</h5>
88+
<SelectValidationTable />
89+
</div>
90+
</div>
91+
</div>
8192
<div className='col-md-offset-1 col-md-8'>
8293
<div className='panel panel-default'>
8394
<div className='panel-heading'>Row Click Example</div>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint max-len: 0 */
2+
/* eslint no-alert: 0 */
3+
/* eslint guard-for-in: 0 */
4+
/* eslint no-console: 0 */
5+
/* eslint no-unused-vars: 0 */
6+
import React from 'react';
7+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
8+
9+
10+
const products = [];
11+
12+
function addProducts(quantity) {
13+
const startId = products.length;
14+
for (let i = 0; i < quantity; i++) {
15+
const id = startId + i;
16+
products.push({
17+
id: id,
18+
name: 'Item name ' + id,
19+
price: 2100 + i
20+
});
21+
}
22+
}
23+
24+
addProducts(5);
25+
26+
function onRowSelect(row, isSelected, e) {
27+
if (isSelected && row.id >= 3) {
28+
alert('The selection only work on key which less than 3');
29+
return false;
30+
}
31+
}
32+
33+
function onSelectAll(isSelected, rows) {
34+
if (isSelected) {
35+
alert('The selection only work on key which less than 3');
36+
return products.map(p => p.id).filter(id => id < 3);
37+
}
38+
}
39+
40+
const selectRowProp = {
41+
mode: 'checkbox',
42+
clickToSelect: true,
43+
onSelect: onRowSelect,
44+
onSelectAll: onSelectAll
45+
};
46+
47+
export default class SelectValidationTable extends React.Component {
48+
render() {
49+
return (
50+
<BootstrapTable data={ products } selectRow={ selectRowProp }>
51+
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
52+
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
53+
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
54+
</BootstrapTable>
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)