Skip to content

Commit 985a171

Browse files
authored
fix #111
* implement selectRow.clickToSelect and selectRow.clickToEdit * add selectRow.clickToSelect and selectRow.clickToEdit stories * add clickToSelect to row selection examples for easier to select row * refine selectRow.nonSelectable * patch tests for selectRow.clickToSelect and selectRow.clickToEdit * patch docs for selectRow.clickToSelect and selectRow.clickToEdit
1 parent bbeb122 commit 985a171

File tree

20 files changed

+588
-103
lines changed

20 files changed

+588
-103
lines changed

docs/row-selection.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The following are available properties in `selectRow`:
1313
* [classes)](#classes)
1414
* [bgColor](#bgColor)
1515
* [nonSelectable)](#nonSelectable)
16+
* [clickToSelect)](#clickToSelect)
17+
* [clickToEdit](#clickToEdit)
1618

1719
#### Optional
1820

@@ -118,4 +120,28 @@ const selectRow = {
118120
mode: 'checkbox',
119121
nonSelectable: [1, 3 ,5]
120122
};
123+
```
124+
125+
## <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
126+
Able to select row when clicking on row.
127+
128+
```js
129+
const selectRow = {
130+
mode: 'checkbox',
131+
clickToSelect: true
132+
};
133+
```
134+
135+
> Note: if you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
136+
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
137+
138+
## <a name='clickToEdit'>selectRow.clickToEdit - [Bool]</a>
139+
Able to click to edit cell and select row
140+
141+
```js
142+
const selectRow = {
143+
mode: 'checkbox',
144+
clickToSelect: true
145+
clickToEdit: true
146+
};
121147
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React from 'react';
2+
3+
import BootstrapTable from 'react-bootstrap-table2';
4+
import Code from 'components/common/code-block';
5+
import { productsGenerator } from 'utils/common';
6+
7+
const products = productsGenerator();
8+
9+
const columns = [{
10+
dataField: 'id',
11+
text: 'Product ID'
12+
}, {
13+
dataField: 'name',
14+
text: 'Product Name'
15+
}, {
16+
dataField: 'price',
17+
text: 'Product Price'
18+
}];
19+
20+
const selectRow = {
21+
mode: 'checkbox',
22+
clickToSelect: true,
23+
clickToEdit: true
24+
};
25+
26+
const cellEdit = {
27+
mode: 'click'
28+
};
29+
30+
const sourceCode = `\
31+
const columns = [{
32+
dataField: 'id',
33+
text: 'Product ID'
34+
}, {
35+
dataField: 'name',
36+
text: 'Product Name'
37+
}, {
38+
dataField: 'price',
39+
text: 'Product Price'
40+
}];
41+
42+
const selectRow = {
43+
mode: 'checkbox',
44+
clickToSelect: true,
45+
clickToEdit: true // Click to edit cell also
46+
};
47+
48+
const cellEdit = {
49+
mode: 'click'
50+
};
51+
52+
<BootstrapTable
53+
keyField='id'
54+
data={ products }
55+
columns={ columns }
56+
selectRow={ selectRow }
57+
/>
58+
`;
59+
60+
export default () => (
61+
<div>
62+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } cellEdit={ cellEdit } />
63+
<Code>{ sourceCode }</Code>
64+
</div>
65+
);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react';
2+
3+
import BootstrapTable from 'react-bootstrap-table2';
4+
import Code from 'components/common/code-block';
5+
import { productsGenerator } from 'utils/common';
6+
7+
const products = productsGenerator();
8+
9+
const columns = [{
10+
dataField: 'id',
11+
text: 'Product ID'
12+
}, {
13+
dataField: 'name',
14+
text: 'Product Name'
15+
}, {
16+
dataField: 'price',
17+
text: 'Product Price'
18+
}];
19+
20+
const selectRow = {
21+
mode: 'checkbox',
22+
clickToSelect: true
23+
};
24+
25+
const sourceCode = `\
26+
const columns = [{
27+
dataField: 'id',
28+
text: 'Product ID'
29+
}, {
30+
dataField: 'name',
31+
text: 'Product Name'
32+
}, {
33+
dataField: 'price',
34+
text: 'Product Price'
35+
}];
36+
37+
const selectRow = {
38+
mode: 'checkbox',
39+
clickToSelect: true
40+
};
41+
42+
<BootstrapTable
43+
keyField='id'
44+
data={ products }
45+
columns={ columns }
46+
selectRow={ selectRow }
47+
/>
48+
`;
49+
50+
export default () => (
51+
<div>
52+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
53+
<Code>{ sourceCode }</Code>
54+
</div>
55+
);

packages/react-bootstrap-table2-example/examples/row-selection/multiple-selection.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const columns = [{
1717
text: 'Product Price'
1818
}];
1919

20-
const selectRowProp = {
21-
mode: 'checkbox'
20+
const selectRow = {
21+
mode: 'checkbox',
22+
clickToSelect: true
2223
};
2324

2425
const sourceCode = `\
@@ -33,21 +34,22 @@ const columns = [{
3334
text: 'Product Price'
3435
}];
3536
36-
const selectRowProp = {
37-
mode: 'checkbox'
37+
const selectRow = {
38+
mode: 'checkbox',
39+
clickToSelect: true
3840
};
3941
4042
<BootstrapTable
4143
keyField='id'
4244
data={ products }
4345
columns={ columns }
44-
selectRow={ selectRowProp }
46+
selectRow={ selectRow }
4547
/>
4648
`;
4749

4850
export default () => (
4951
<div>
50-
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRowProp } />
52+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
5153
<Code>{ sourceCode }</Code>
5254
</div>
5355
);

packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const columns = [{
1919

2020
const selectRow = {
2121
mode: 'checkbox',
22+
clickToSelect: true,
2223
nonSelectable: [0, 2, 4]
2324
};
2425

@@ -36,6 +37,7 @@ const columns = [{
3637
3738
const selectRow = {
3839
mode: 'checkbox',
40+
clickToSelect: true,
3941
nonSelectable: [0, 2, 4]
4042
};
4143

packages/react-bootstrap-table2-example/examples/row-selection/selection-bgcolor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ const columns = [{
2020

2121
const selectRow1 = {
2222
mode: 'checkbox',
23+
clickToSelect: true,
2324
bgColor: '#00BFFF'
2425
};
2526

2627
const selectRow2 = {
2728
mode: 'checkbox',
29+
clickToSelect: true,
2830
bgColor: (row, rowIndex) => (rowIndex > 1 ? '#00BFFF' : '#00FFFF')
2931
};
3032

@@ -42,6 +44,7 @@ const columns = [{
4244
4345
const selectRow = {
4446
mode: 'checkbox',
47+
clickToSelect: true,
4548
bgColor: '#00BFFF'
4649
};
4750
@@ -67,6 +70,7 @@ const columns = [{
6770
6871
const selectRow = {
6972
mode: 'checkbox',
73+
clickToSelect: true,
7074
bgColor: (row, rowIndex) => (rowIndex > 1 ? '#00BFFF' : '#00FFFF')
7175
};
7276

packages/react-bootstrap-table2-example/examples/row-selection/selection-class.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ const columns = [{
2020

2121
const selectRow1 = {
2222
mode: 'checkbox',
23+
clickToSelect: true,
2324
classes: 'selection-row'
2425
};
2526

2627
const selectRow2 = {
2728
mode: 'checkbox',
29+
clickToSelect: true,
2830
classes: (row, rowIndex) =>
2931
(rowIndex > 1 ? 'row-index-bigger-than-2101' : 'row-index-small-than-2101')
3032
};
@@ -43,6 +45,7 @@ const columns = [{
4345
4446
const selectRow = {
4547
mode: 'checkbox',
48+
clickToSelect: true,
4649
classes: 'selection-row'
4750
};
4851
@@ -68,6 +71,7 @@ const columns = [{
6871
6972
const selectRow = {
7073
mode: 'checkbox',
74+
clickToSelect: true,
7175
classes: (row, rowIndex) =>
7276
(rowIndex > 1 ? 'row-index-bigger-than-2101' : 'row-index-small-than-2101')
7377
};

packages/react-bootstrap-table2-example/examples/row-selection/selection-style.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ const columns = [{
2020

2121
const selectRow1 = {
2222
mode: 'checkbox',
23+
clickToSelect: true,
2324
style: { backgroundColor: '#c8e6c9' }
2425
};
2526

2627
const selectRow2 = {
2728
mode: 'checkbox',
29+
clickToSelect: true,
2830
style: (row, rowIndex) => {
2931
const backgroundColor = rowIndex > 1 ? '#00BFFF' : '#00FFFF';
3032
return { backgroundColor };
@@ -45,6 +47,7 @@ const columns = [{
4547
4648
const selectRow = {
4749
mode: 'checkbox',
50+
clickToSelect: true,
4851
style: { backgroundColor: '#c8e6c9' }
4952
};
5053
@@ -70,6 +73,7 @@ const columns = [{
7073
7174
const selectRow = {
7275
mode: 'checkbox',
76+
clickToSelect: true,
7377
style: (row, rowIndex) => {
7478
const backgroundColor = rowIndex > 1 ? '#00BFFF' : '#00FFFF';
7579
return { backgroundColor };

packages/react-bootstrap-table2-example/examples/row-selection/single-selection.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const columns = [{
1717
text: 'Product Price'
1818
}];
1919

20-
const selectRowProp = {
21-
mode: 'radio'
20+
const selectRow = {
21+
mode: 'radio',
22+
clickToSelect: true
2223
};
2324

2425
const sourceCode = `\
@@ -33,21 +34,22 @@ const columns = [{
3334
text: 'Product Price'
3435
}];
3536
36-
const selectRowProp = {
37-
mode: 'radio'
37+
const selectRow = {
38+
mode: 'radio',
39+
clickToSelect: true
3840
};
3941
4042
<BootstrapTable
4143
keyField='id'
4244
data={ products }
4345
columns={ columns }
44-
selectRow={ selectRowProp }
46+
selectRow={ selectRow }
4547
/>
4648
`;
4749

4850
export default () => (
4951
<div>
50-
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRowProp } />
52+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
5153
<Code>{ sourceCode }</Code>
5254
</div>
5355
);

packages/react-bootstrap-table2-example/stories/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import CellEditWithRedux from 'examples/cell-edit/cell-edit-with-redux-table';
5353
// work on row selection
5454
import SingleSelectionTable from 'examples/row-selection/single-selection';
5555
import MultipleSelectionTable from 'examples/row-selection/multiple-selection';
56+
import ClickToSelectTable from 'examples/row-selection/click-to-select';
57+
import ClickToSelectWithCellEditTable from 'examples/row-selection/click-to-select-with-cell-edit';
5658
import SelectionStyleTable from 'examples/row-selection/selection-style';
5759
import SelectionClassTable from 'examples/row-selection/selection-class';
5860
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
@@ -119,6 +121,8 @@ storiesOf('Cell Editing', module)
119121
storiesOf('Row Selection', module)
120122
.add('Single Selection', () => <SingleSelectionTable />)
121123
.add('Multiple Selection', () => <MultipleSelectionTable />)
124+
.add('Click to Select', () => <ClickToSelectTable />)
125+
.add('Click to Select and Edit Cell', () => <ClickToSelectWithCellEditTable />)
122126
.add('Selection Style', () => <SelectionStyleTable />)
123127
.add('Selection Class', () => <SelectionClassTable />)
124128
.add('Selection Background Color', () => <SelectionBgColorTable />)

0 commit comments

Comments
 (0)