Skip to content

Commit 77b8ed5

Browse files
authored
Merge pull request #926 from react-bootstrap-table/develop
20190427 release
2 parents e2e6c51 + 6bc54ef commit 77b8ed5

File tree

13 files changed

+179
-27
lines changed

13 files changed

+179
-27
lines changed

docs/row-selection.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [hideSelectAll](#hideSelectAll)
2121
* [selectionRenderer](#selectionRenderer)
2222
* [selectionHeaderRenderer](#selectionHeaderRenderer)
23+
* [headerColumnStyle](#headerColumnStyle)
2324

2425
### <a name="mode">selectRow.mode - [String]</a>
2526

@@ -198,6 +199,31 @@ const selectRow = {
198199

199200
> By default, `react-bootstrap-table2` will help you to handle the click event, it's not necessary to handle again by developer.
200201
202+
203+
### <a name='headerColumnStyle'>selectRow.headerColumnStyle - [Object | Function]</a>
204+
A way to custome the selection header cell. `headerColumnStyle` not only accept a simple style object but also a callback function for more flexible customization:
205+
206+
### Style Object
207+
208+
```js
209+
const selectRow = {
210+
mode: 'checkbox',
211+
headerColumnStyle: { backgroundColor: 'blue' }
212+
};
213+
```
214+
215+
### Callback Function
216+
217+
```js
218+
const selectRow = {
219+
mode: 'checkbox',
220+
headerColumnStyle: (status) => (
221+
// status available value is checked, indeterminate and unchecked
222+
return { backgroundColor: 'blue' };
223+
)
224+
};
225+
```
226+
201227
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
202228
This callback function will be called when a row is select/unselect and pass following three arguments:
203229
`row`, `isSelect`, `rowIndex` and `e`.

packages/react-bootstrap-table2-example/examples/basic/exposed-function.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ class ExposedFunctionTable extends React.Component {
4545
console.log(this.node.table.props.data);
4646
}
4747
48+
handleGetCurrentData = () => {
49+
console.log(this.node.table.props.data);
50+
}
51+
4852
handleGetSelectedData = () => {
49-
console.log(this.node.selectionContext.state.selected);
53+
console.log(this.node.selectionContext.selected);
5054
}
5155
5256
handleGetExpandedData = () => {
@@ -117,7 +121,7 @@ export default class ExposedFunctionTable extends React.Component {
117121
}
118122

119123
handleGetSelectedData = () => {
120-
console.log(this.node.selectionContext.state.selected);
124+
console.log(this.node.selectionContext.selected);
121125
}
122126

123127
handleGetExpandedData = () => {

packages/react-bootstrap-table2-example/examples/row-expand/expand-only-one.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const columns = [{
4343
}];
4444
4545
const expandRow = {
46+
onlyOneExpanding: true,
4647
renderer: row => (
4748
<div>
4849
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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(2);
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 selectRow1 = {
21+
mode: 'checkbox',
22+
clickToSelect: true,
23+
headerColumnStyle: {
24+
backgroundColor: 'blue'
25+
}
26+
};
27+
28+
const sourceCode1 = `\
29+
import BootstrapTable from 'react-bootstrap-table-next';
30+
31+
const columns = ...
32+
33+
const selectRow = {
34+
mode: 'checkbox',
35+
clickToSelect: true,
36+
headerColumnStyle: {
37+
backgroundColor: 'blue'
38+
}
39+
};
40+
41+
<BootstrapTable
42+
keyField='id'
43+
data={ products }
44+
columns={ columns }
45+
selectRow={ selectRow }
46+
/>
47+
`;
48+
49+
const selectRow2 = {
50+
mode: 'checkbox',
51+
clickToSelect: true,
52+
headerColumnStyle: (status) => {
53+
if (status === 'checked') {
54+
return {
55+
backgroundColor: 'yellow'
56+
};
57+
} else if (status === 'indeterminate') {
58+
return {
59+
backgroundColor: 'pink'
60+
};
61+
} else if (status === 'unchecked') {
62+
return {
63+
backgroundColor: 'grey'
64+
};
65+
}
66+
return {};
67+
}
68+
};
69+
70+
const sourceCode2 = `\
71+
import BootstrapTable from 'react-bootstrap-table-next';
72+
73+
const columns = ...
74+
75+
const selectRow = {
76+
mode: 'checkbox',
77+
clickToSelect: true,
78+
headerColumnStyle: (status) => {
79+
if (status === 'checked') {
80+
return {
81+
backgroundColor: 'yellow'
82+
};
83+
} else if (status === 'indeterminate') {
84+
return {
85+
backgroundColor: 'pink'
86+
};
87+
} else if (status === 'unchecked') {
88+
return {
89+
backgroundColor: 'grey'
90+
};
91+
}
92+
return {};
93+
}
94+
};
95+
96+
<BootstrapTable
97+
keyField='id'
98+
data={ products }
99+
columns={ columns }
100+
selectRow={ selectRow }
101+
/>
102+
`;
103+
104+
export default () => (
105+
<div>
106+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow1 } />
107+
<Code>{ sourceCode1 }</Code>
108+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow2 } />
109+
<Code>{ sourceCode2 }</Code>
110+
</div>
111+
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ import SelectionWithExpansionTable from 'examples/row-selection/selection-with-e
142142
import SelectionNoDataTable from 'examples/row-selection/selection-no-data';
143143
import SelectionStyleTable from 'examples/row-selection/selection-style';
144144
import SelectionClassTable from 'examples/row-selection/selection-class';
145+
import HeaderStyleTable from 'examples/row-selection/header-style';
145146
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
146147
import CustomSelectionTable from 'examples/row-selection/custom-selection';
147148
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
@@ -385,6 +386,7 @@ storiesOf('Row Selection', module)
385386
.add('Selection without Data', () => <SelectionNoDataTable />)
386387
.add('Selection Style', () => <SelectionStyleTable />)
387388
.add('Selection Class', () => <SelectionClassTable />)
389+
.add('Custom Selection Column Header Style', () => <HeaderStyleTable />)
388390
.add('Hide Select All', () => <HideSelectAllTable />)
389391
.add('Custom Selection', () => <CustomSelectionTable />)
390392
.add('Selection Background Color', () => <SelectionBgColorTable />)

packages/react-bootstrap-table2-toolkit/src/csv/exporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const transform = (
4242
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
4343
}
4444
if (m.type === String) {
45-
return `"${cellContent}"`;
45+
return `"${`${cellContent}`.replace(/"/g, '""')}"`;
4646
}
4747
return cellContent;
4848
}).join(separator)).join('\n');

packages/react-bootstrap-table2-toolkit/src/search/SearchBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SearchBar.defaultProps = {
9696
placeholder: 'Search',
9797
delay: 250,
9898
searchText: '',
99-
tableId: 0
99+
tableId: '0'
100100
};
101101

102102
export default SearchBar;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ BootstrapTable.propTypes = {
167167
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
168168
hideSelectColumn: PropTypes.bool,
169169
selectionRenderer: PropTypes.func,
170-
selectionHeaderRenderer: PropTypes.func
170+
selectionHeaderRenderer: PropTypes.func,
171+
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
171172
}),
172173
expandRow: PropTypes.shape({
173174
renderer: PropTypes.func,

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import _ from './utils';
88
class Cell extends eventDelegater(Component) {
99
constructor(props) {
1010
super(props);
11-
this.handleEditingCell = this.handleEditingCell.bind(this);
11+
this.createHandleEditingCell = this.createHandleEditingCell.bind(this);
1212
}
1313

1414
shouldComponentUpdate(nextProps) {
@@ -43,17 +43,10 @@ class Cell extends eventDelegater(Component) {
4343
return shouldUpdate;
4444
}
4545

46-
handleEditingCell(e) {
47-
const { column, onStart, rowIndex, columnIndex, clickToEdit, dbclickToEdit } = this.props;
48-
const { events } = column;
49-
if (events) {
50-
if (clickToEdit) {
51-
const customClick = events.onClick;
52-
if (_.isFunction(customClick)) customClick(e);
53-
} else if (dbclickToEdit) {
54-
const customDbClick = events.onDoubleClick;
55-
if (_.isFunction(customDbClick)) customDbClick(e);
56-
}
46+
createHandleEditingCell = originFunc => (e) => {
47+
const { onStart, rowIndex, columnIndex, clickToEdit, dbclickToEdit } = this.props;
48+
if ((clickToEdit || dbclickToEdit) && _.isFunction(originFunc)) {
49+
originFunc(e);
5750
}
5851
if (onStart) {
5952
onStart(rowIndex, columnIndex);
@@ -85,9 +78,9 @@ class Cell extends eventDelegater(Component) {
8578
}
8679

8780
if (clickToEdit && editable) {
88-
attrs.onClick = this.handleEditingCell;
81+
attrs.onClick = this.createHandleEditingCell(attrs.onClick);
8982
} else if (dbclickToEdit && editable) {
90-
attrs.onDoubleClick = this.handleEditingCell;
83+
attrs.onDoubleClick = this.createHandleEditingCell(attrs.onDoubleClick);
9184
}
9285

9386
return (

packages/react-bootstrap-table2/src/contexts/row-expand-context.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import PropTypes from 'prop-types';
44
import dataOperator from '../store/operators';
5+
import _ from '../utils';
56

67
const RowExpandContext = React.createContext();
78

@@ -81,7 +82,7 @@ class RowExpandProvider extends React.Component {
8182
if (expandAll) {
8283
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
8384
} else {
84-
currExpanded = expanded.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
85+
currExpanded = expanded.filter(s => typeof data.find(d => _.get(d, keyField) === s) === 'undefined');
8586
}
8687

8788
if (onExpandAll) {

0 commit comments

Comments
 (0)