Skip to content

Commit acb9c9f

Browse files
authored
Merge pull request #1166 from react-bootstrap-table/develop
20191116 release
2 parents 5a44384 + 6d13a86 commit acb9c9f

File tree

12 files changed

+204
-7
lines changed

12 files changed

+204
-7
lines changed

docs/row-selection.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# Row selection
3-
`react-bootstrap-table2` supports the row selection feature. By passing prop `selectRow` to enable row selection. When you enable this feature, `react-bootstrap-table2` will prepend a new selection column.
3+
`react-bootstrap-table2` supports the row selection feature. By passing prop `selectRow` to enable row selection. When you enable this feature, `react-bootstrap-table2` will prepend a new selection column.
44

55
## Required
66
* [mode (**required**)](#mode)
@@ -11,6 +11,8 @@
1111
* [classes)](#classes)
1212
* [bgColor](#bgColor)
1313
* [nonSelectable)](#nonSelectable)
14+
* [nonSelectableStyle](#nonSelectableStyle)
15+
* [nonSelectableClasses](#nonSelectableClasses)
1416
* [clickToSelect)](#clickToSelect)
1517
* [clickToExpand)](#clickToExpand)
1618
* [clickToEdit](#clickToEdit)
@@ -139,6 +141,54 @@ const selectRow = {
139141
};
140142
```
141143

144+
### <a name='nonSelectableStyle'>selectRow.nonSelectableStyle - [Object | Function]</a>
145+
This prop allow you to customize the non selectable rows. `selectRow.nonSelectableStyle` accepts an style object
146+
and a callback function for more flexible customization.
147+
148+
### Style Object
149+
150+
```js
151+
const selectRow = {
152+
mode: 'checkbox',
153+
nonSelectable: [1, 3 ,5],
154+
nonSelectableStyle: { backgroundColor: 'gray' }
155+
};
156+
```
157+
158+
### Callback Function
159+
160+
```js
161+
const selectRow = {
162+
mode: 'checkbox',
163+
nonSelectable: [1, 3 ,5],
164+
nonSelectableStyle: (row, rowIndex) => { return ...; }
165+
};
166+
```
167+
168+
### <a name='nonSelectableClasses'>selectRow.nonSelectableClasses - [String | Function]</a>
169+
This prop allow you to set a custom class for the non selectable rows, or use a callback function for more
170+
flexible customization
171+
172+
### String
173+
174+
```js
175+
const selectRow = {
176+
mode: 'checkbox',
177+
nonSelectable: [1, 3 ,5],
178+
nonSelectableClasses: 'my-class'
179+
};
180+
```
181+
182+
### Callback Function
183+
184+
```js
185+
const selectRow = {
186+
mode: 'checkbox',
187+
nonSelectable: [1, 3 ,5],
188+
nonSelectableClasses: (row, rowIndex) => { return ...; }
189+
};
190+
```
191+
142192
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
143193
Allow user to select row by clicking on the row.
144194

@@ -149,7 +199,7 @@ const selectRow = {
149199
};
150200
```
151201

152-
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
202+
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
153203
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
154204
155205
### <a name='clickToExpand'>selectRow.clickToExpand - [Bool]</a>
@@ -307,7 +357,7 @@ const selectRow = {
307357
mode: 'checkbox',
308358
onSelectAll: (isSelect, rows, e) => {
309359
if (isSelect && SOME_CONDITION) {
310-
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
360+
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
311361
}
312362
}
313363
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
3+
import BootstrapTable from 'react-bootstrap-table-next';
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+
nonSelectable: [0, 2, 4],
24+
nonSelectableClasses: 'row-index-bigger-than-2101'
25+
};
26+
27+
const sourceCode = `\
28+
import BootstrapTable from 'react-bootstrap-table-next';
29+
30+
const columns = [{
31+
dataField: 'id',
32+
text: 'Product ID'
33+
}, {
34+
dataField: 'name',
35+
text: 'Product Name'
36+
}, {
37+
dataField: 'price',
38+
text: 'Product Price'
39+
}];
40+
41+
const selectRow = {
42+
mode: 'checkbox',
43+
clickToSelect: true,
44+
nonSelectable: [0, 2, 4],
45+
nonSelectableClasses: 'row-index-bigger-than-2101'
46+
};
47+
48+
<BootstrapTable
49+
keyField='id'
50+
data={ products }
51+
columns={ columns }
52+
selectRow={ selectRow }
53+
/>
54+
`;
55+
56+
export default () => (
57+
<div>
58+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
59+
<Code>{ sourceCode }</Code>
60+
</div>
61+
);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
3+
import BootstrapTable from 'react-bootstrap-table-next';
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+
nonSelectable: [0, 2, 4],
24+
nonSelectableStyle: { backgroundColor: 'gray' }
25+
};
26+
27+
const sourceCode = `\
28+
import BootstrapTable from 'react-bootstrap-table-next';
29+
30+
const columns = [{
31+
dataField: 'id',
32+
text: 'Product ID'
33+
}, {
34+
dataField: 'name',
35+
text: 'Product Name'
36+
}, {
37+
dataField: 'price',
38+
text: 'Product Price'
39+
}];
40+
41+
const selectRow = {
42+
mode: 'checkbox',
43+
clickToSelect: true,
44+
nonSelectable: [0, 2, 4],
45+
nonSelectableStyle: { backgroundColor: 'gray' }
46+
};
47+
48+
<BootstrapTable
49+
keyField='id'
50+
data={ products }
51+
columns={ columns }
52+
selectRow={ selectRow }
53+
/>
54+
`;
55+
56+
export default () => (
57+
<div>
58+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
59+
<Code>{ sourceCode }</Code>
60+
</div>
61+
);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ import HeaderStyleTable from 'examples/row-selection/header-style';
152152
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
153153
import CustomSelectionTable from 'examples/row-selection/custom-selection';
154154
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
155+
import NonSelectableRowsStyleTable from 'examples/row-selection/non-selectable-rows-style';
156+
import NonSelectableRowsClassTable from 'examples/row-selection/non-selectable-rows-class';
155157
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
156158
import SelectionHooks from 'examples/row-selection/selection-hooks';
157159
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
@@ -410,6 +412,8 @@ storiesOf('Row Selection', module)
410412
.add('Custom Selection', () => <CustomSelectionTable />)
411413
.add('Selection Background Color', () => <SelectionBgColorTable />)
412414
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
415+
.add('Not Selectabled Rows Style', () => <NonSelectableRowsStyleTable />)
416+
.add('Not Selectabled Rows Class', () => <NonSelectableRowsClassTable />)
413417
.add('Selection Hooks', () => <SelectionHooks />)
414418
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
415419
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)

packages/react-bootstrap-table2/src/bootstrap-table.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ BootstrapTable.propTypes = {
182182
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
183183
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
184184
nonSelectable: PropTypes.array,
185+
nonSelectableStyle: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
186+
nonSelectableClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
185187
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
186188
hideSelectColumn: PropTypes.bool,
187189
selectionRenderer: PropTypes.func,

packages/react-bootstrap-table2/src/filters.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Filters = (props) => {
2121
columns.forEach((column, i) => {
2222
filterColumns.push(<FiltersCell
2323
index={ i }
24+
key={ column.dataField }
2425
column={ column }
2526
currFilters={ currFilters }
2627
onExternalFilter={ onExternalFilter }

packages/react-bootstrap-table2/src/row-expand/expand-cell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class ExpandCell extends Component {
4444
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
4545

4646
return (
47-
<td onClick={ this.handleClick } { ...attrs }>
47+
<td className="expand-cell" onClick={ this.handleClick } { ...attrs }>
4848
{
4949
expandColumnRenderer ? expandColumnRenderer({
5050
expandable,

packages/react-bootstrap-table2/src/row-expand/expand-header-cell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class ExpansionHeaderCell extends Component {
2828
};
2929

3030
return (
31-
<th data-row-selection { ...attrs }>
31+
<th className="expand-cell-header" data-row-selection { ...attrs }>
3232
{
3333
expandHeaderColumnRenderer ?
3434
expandHeaderColumnRenderer({ isAnyExpands }) :

packages/react-bootstrap-table2/src/row-selection/row-consumer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default (Component) => {
99
const key = props.value;
1010
const selected = _.contains(selectRow.selected, key);
1111
const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
12+
const notSelectable = _.contains(selectRow.nonSelectable, key);
1213

1314
let {
1415
style,
@@ -38,6 +39,22 @@ export default (Component) => {
3839
}
3940
}
4041

42+
if (notSelectable) {
43+
const notSelectableStyle = _.isFunction(selectRow.nonSelectableStyle)
44+
? selectRow.nonSelectableStyle(props.row, props.rowIndex)
45+
: selectRow.nonSelectableStyle;
46+
47+
const notSelectableClasses = _.isFunction(selectRow.nonSelectableClasses)
48+
? selectRow.nonSelectableClasses(props.row, props.rowIndex)
49+
: selectRow.nonSelectableClasses;
50+
51+
style = {
52+
...style,
53+
...notSelectableStyle
54+
};
55+
className = cs(className, notSelectableClasses) || undefined;
56+
}
57+
4158
return (
4259
<Component
4360
{ ...props }

packages/react-bootstrap-table2/src/row-selection/selection-cell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class SelectionCell extends Component {
8686
<BootstrapContext.Consumer>
8787
{
8888
({ bootstrap4 }) => (
89-
<td onClick={ this.handleClick } { ...attrs }>
89+
<td className="selection-cell" onClick={ this.handleClick } { ...attrs }>
9090
{
9191
selectionRenderer ? selectionRenderer({
9292
mode: inputType,

0 commit comments

Comments
 (0)