Skip to content

Commit 64c113d

Browse files
authored
Merge pull request #1023 from react-bootstrap-table/develop
20190721 release
2 parents 5e8bb34 + db22bb9 commit 64c113d

File tree

20 files changed

+354
-22
lines changed

20 files changed

+354
-22
lines changed

docs/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ import overlayFactory from 'react-bootstrap-table2-overlay';
9898
Actually, `react-bootstrap-table-overlay` is depends on [`react-loading-overlay`](https://github.com/derrickpelletier/react-loading-overlay) and `overlayFactory` just a factory function and you can pass any props which available for `react-loading-overlay`:
9999

100100
```js
101-
overlay={ overlayFactory({ spinner: true, background: 'rgba(192,192,192,0.3)' }) }
101+
overlay={
102+
overlayFactory({
103+
spinner: true,
104+
styles: {
105+
overlay: (base) => ({...base, background: 'rgba(255, 0, 0, 0.5)'})
106+
}
107+
})
108+
}
102109
```
103110

104111
### <a name='caption'>caption - [String | Node]</a>
@@ -334,4 +341,4 @@ handleDataChange = ({ dataSize }) => {
334341
onDataSizeChange={ handleDataChange }
335342
....
336343
/>
337-
```
344+
```

docs/columns.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Available properties in a column object:
1111
* [hidden](#hidden)
1212
* [formatter](#formatter)
1313
* [formatExtraData](#formatExtraData)
14+
* [type](#type)
1415
* [sort](#sort)
1516
* [sortFunc](#sortFunc)
1617
* [sortCaret](#sortCaret)
@@ -132,6 +133,10 @@ The third argument: `components` have following specified properties:
132133
## <a name='formatExtraData'>column.formatExtraData - [Any]</a>
133134
It's only used for [`column.formatter`](#formatter), you can define any value for it and will be passed as fourth argument for [`column.formatter`](#formatter) callback function.
134135

136+
## <a name='type'>column.type - [String]</a>
137+
Specify the data type on column. Available value so far is `string`, `number`, `bool` and `date`. Default is `string`.
138+
`column.type` can be used when you enable the cell editing and want to save your cell data with correct data type.
139+
135140
## <a name='sort'>column.sort - [Bool]</a>
136141
Enable the column sort via a `true` value given.
137142

docs/row-expand.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@
1818
* [expandColumnPosition](#expandColumnPosition)
1919
* [expandColumnRenderer](#expandColumnRenderer)
2020
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
21+
* [parentClassName](#parentClassName)
2122

2223
### <a name="renderer">expandRow.renderer - [Function]</a>
2324

2425
Specify the content of expand row, `react-bootstrap-table2` will pass a row object as argument and expect return a react element.
2526

2627
#### values
2728
* **row**
29+
* **rowIndex**
2830

2931
#### examples
3032

3133
```js
3234
const expandRow = {
33-
renderer: row => (
35+
renderer: (row, rowIndex) => (
3436
<div>
3537
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
3638
<p>You can render anything here, also you can add additional data on every row object</p>
@@ -165,3 +167,24 @@ const expandRow = {
165167
expandColumnPosition: 'right'
166168
};
167169
```
170+
171+
### <a name='parentClassName'>expandRow.parentClassName - [String | Function]</a>
172+
Apply the custom class name on parent row of expanded row. For example:
173+
174+
```js
175+
const expandRow = {
176+
renderer: (row) => ...,
177+
parentClassName: 'foo'
178+
};
179+
```
180+
Below case is more flexible way to custom the class name:
181+
182+
```js
183+
const expandRow = {
184+
renderer: (row) => ...,
185+
parentClassName: (isExpanded, row, rowIndex) => {
186+
if (rowIndex > 2) return 'foo';
187+
return 'bar';
188+
}
189+
};
190+
```

packages/react-bootstrap-table2-editor/src/context.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,21 @@ export default (
5656
}
5757

5858
handleCellUpdate(row, column, newValue) {
59+
const newValueWithType = dataOperator.typeConvert(column.type, newValue);
5960
const { cellEdit } = this.props;
6061
const { beforeSaveCell } = cellEdit.options;
6162
const oldValue = _.get(row, column.dataField);
6263
const beforeSaveCellDone = (result = true) => {
6364
if (result) {
64-
this.doUpdate(row, column, newValue);
65+
this.doUpdate(row, column, newValueWithType);
6566
} else {
6667
this.escapeEditing();
6768
}
6869
};
6970
if (_.isFunction(beforeSaveCell)) {
7071
const result = beforeSaveCell(
7172
oldValue,
72-
newValue,
73+
newValueWithType,
7374
row,
7475
column,
7576
beforeSaveCellDone
@@ -78,7 +79,7 @@ export default (
7879
return;
7980
}
8081
}
81-
this.doUpdate(row, column, newValue);
82+
this.doUpdate(row, column, newValueWithType);
8283
}
8384

8485
doUpdate(row, column, newValue) {
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* eslint prefer-template: 0 */
2+
import React from 'react';
3+
import BootstrapTable from 'react-bootstrap-table-next';
4+
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
5+
import Code from 'components/common/code-block';
6+
import { stockGenerator } from 'utils/common';
7+
8+
const products = stockGenerator();
9+
10+
const columns = [{
11+
dataField: 'id',
12+
text: 'Stock ID'
13+
}, {
14+
dataField: 'name',
15+
text: 'Stock Name'
16+
}, {
17+
dataField: 'price',
18+
text: 'Price',
19+
type: 'number'
20+
}, {
21+
dataField: 'visible',
22+
text: 'Visible?',
23+
type: 'bool',
24+
editor: {
25+
type: Type.CHECKBOX,
26+
value: 'true:false'
27+
}
28+
}, {
29+
dataField: 'inStockDate',
30+
text: 'Stock Date',
31+
type: 'date',
32+
formatter: (cell) => {
33+
let dateObj = cell;
34+
if (typeof cell !== 'object') {
35+
dateObj = new Date(cell);
36+
}
37+
return `${('0' + dateObj.getUTCDate()).slice(-2)}/${('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/${dateObj.getUTCFullYear()}`;
38+
},
39+
editor: {
40+
type: Type.DATE
41+
}
42+
}];
43+
44+
const sourceCode = `\
45+
import BootstrapTable from 'react-bootstrap-table-next';
46+
import cellEditFactory from 'react-bootstrap-table2-editor';
47+
48+
const columns = [{
49+
dataField: 'id',
50+
text: 'Stock ID'
51+
}, {
52+
dataField: 'name',
53+
text: 'Stock Name'
54+
}, {
55+
dataField: 'price',
56+
text: 'Price',
57+
type: 'number'
58+
}, {
59+
dataField: 'visible',
60+
text: 'Visible?',
61+
type: 'bool',
62+
editor: {
63+
type: Type.CHECKBOX,
64+
value: 'true:false'
65+
}
66+
}, {
67+
dataField: 'inStockDate',
68+
text: 'Stock Date',
69+
type: 'date',
70+
formatter: (cell) => {
71+
let dateObj = cell;
72+
if (typeof cell !== 'object') {
73+
dateObj = new Date(cell);
74+
}
75+
return \`$\{('0' + dateObj.getUTCDate()).slice(-2)}/$\{('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/$\{dateObj.getUTCFullYear()}\`;
76+
},
77+
editor: {
78+
type: Type.DATE
79+
}
80+
}];
81+
82+
function afterSaveCell(oldValue, newValue) {
83+
console.log('--after save cell--');
84+
console.log('New Value was apply as');
85+
console.log(newValue);
86+
console.log(\`and the type is $\{typeof newValue}\`);
87+
}
88+
89+
<BootstrapTable
90+
keyField="id"
91+
data={ products }
92+
columns={ columns }
93+
cellEdit={ cellEditFactory({
94+
mode: 'click',
95+
blurToSave: true,
96+
afterSaveCell
97+
}) }
98+
/>
99+
`;
100+
101+
function afterSaveCell(oldValue, newValue) {
102+
console.log('--after save cell--');
103+
console.log('New Value was apply as');
104+
console.log(newValue);
105+
console.log(`and the type is ${typeof newValue}`);
106+
}
107+
108+
export default () => (
109+
<div>
110+
<h3>Save Cell Value with Specified Data Type</h3>
111+
<BootstrapTable
112+
keyField="id"
113+
data={ products }
114+
columns={ columns }
115+
cellEdit={ cellEditFactory({
116+
mode: 'click',
117+
blurToSave: true,
118+
afterSaveCell
119+
}) }
120+
/>
121+
<Code>{ sourceCode }</Code>
122+
</div>
123+
);

packages/react-bootstrap-table2-example/examples/column-filter/custom-filter-logic.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import BootstrapTable from 'react-bootstrap-table-next';
1212
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
1313
1414
class Table extends React.Component {
15-
filterByPrice = filterVal =>
16-
products.filter(product => product.price == filterVal);
15+
filterByPrice = (filterVal) => {
16+
if (filterVal) {
17+
return products.filter(product => product.price == filterVal);
18+
}
19+
return products;
20+
}
1721
1822
render() {
1923
const columns = [{
@@ -46,8 +50,12 @@ class Table extends React.Component {
4650
`;
4751

4852
export default class Table extends React.Component {
49-
filterByPrice = filterVal =>
50-
products.filter(product => product.price == filterVal);
53+
filterByPrice = (filterVal) => {
54+
if (filterVal) {
55+
return products.filter(product => product.price == filterVal);
56+
}
57+
return products;
58+
}
5159

5260
render() {
5361
const columns = [{
@@ -67,7 +75,7 @@ export default class Table extends React.Component {
6775

6876
return (
6977
<div>
70-
<h2>Implement a eq filter on product price column</h2>
78+
<h2>Implement Custom Filter</h2>
7179
<BootstrapTable
7280
keyField="id"
7381
data={ products }

packages/react-bootstrap-table2-example/examples/loading-overlay/table-overlay.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const RemotePagination = ({ loading, data, page, sizePerPage, onTableChange, tot
3636
columns={ columns }
3737
pagination={ paginationFactory({ page, sizePerPage, totalSize }) }
3838
onTableChange={ onTableChange }
39-
overlay={ overlayFactory({ spinner: true, background: 'rgba(192,192,192,0.3)' }) }
39+
overlay={ overlayFactory({ spinner: true, styles: { overlay: (base) => ({...base, background: 'rgba(255, 0, 0, 0.5)'}) } }) }
4040
/>
4141
<Code>{ sourceCode }</Code>
4242
</div>
@@ -101,7 +101,12 @@ const RemotePagination = ({ loading, data, page, sizePerPage, onTableChange, tot
101101
columns={ columns }
102102
pagination={ paginationFactory({ page, sizePerPage, totalSize }) }
103103
onTableChange={ onTableChange }
104-
overlay={ overlayFactory({ spinner: true, background: 'rgba(192,192,192,0.3)' }) }
104+
overlay={
105+
overlayFactory({
106+
spinner: true,
107+
styles: { overlay: base => ({ ...base, background: 'rgba(255, 0, 0, 0.5)' }) }
108+
})
109+
}
105110
/>
106111
<Code>{ sourceCode }</Code>
107112
</div>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const columns = [{
1818
}];
1919

2020
const expandRow = {
21-
renderer: row => (
21+
renderer: (row, rowIndex) => (
2222
<div>
23-
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
23+
<p>{ `This Expand row is belong to rowKey ${row.id} and index: ${rowIndex}` }</p>
2424
<p>You can render anything here, also you can add additional data on every row object</p>
2525
<p>expandRow.renderer callback will pass the origin row object to you</p>
2626
</div>

0 commit comments

Comments
 (0)