Compare commits

...

25 Commits

Author SHA1 Message Date
AllenFang
6530ff1570 Publish
- react-bootstrap-table-next@3.1.7
2019-07-22 20:22:38 +08:00
AllenFang
9af61b54b1 Publish
- react-bootstrap-table2-editor@1.3.1
2019-07-22 20:22:09 +08:00
AllenFang
72f7333a34 Publish
- react-bootstrap-table2-editor@1.3.0
 - react-bootstrap-table2-example@1.0.28
 - react-bootstrap-table-next@3.1.6
2019-07-22 20:14:49 +08:00
Allen
64c113da26 Merge pull request #1023 from react-bootstrap-table/develop
20190721 release
2019-07-22 20:08:57 +08:00
AllenFang
db22bb9adb fix #1015 2019-07-21 16:52:28 +08:00
AllenFang
d7e1f1dfd0 fix #1014 2019-07-21 16:45:11 +08:00
AllenFang
c277c8139e fix #1007 2019-07-21 16:07:26 +08:00
AllenFang
ec4864da5c fix #993 2019-07-13 16:28:48 +08:00
AllenFang
92f1449177 fix #1004 2019-07-13 15:28:12 +08:00
Gena M
46258b0264 Update README, overlayFactory example (#997)
Update example of usage `overlayFactory` according to "react-loading-overlay" documentation.
2019-07-13 13:57:03 +08:00
AllenFang
5e8bb3426a Publish
- react-bootstrap-table2-example@1.0.27
 - react-bootstrap-table2-filter@1.1.10
 - react-bootstrap-table2-paginator@2.0.7
 - react-bootstrap-table-next@3.1.5
2019-06-25 23:13:31 +08:00
Allen
03f2ce4792 Merge pull request #991 from react-bootstrap-table/develop
20190625 release
2019-06-25 23:12:05 +08:00
AllenFang
7382010822 fix #970 2019-06-22 15:47:21 +08:00
Allen
a1a59f9419 fix #980 (#987) 2019-06-22 15:24:28 +08:00
Allen
59f184d74d fix #971 (#986) 2019-06-22 14:45:53 +08:00
Allen
643b9bca5f Merge pull request #985 from react-bootstrap-table/bugfix/979
Fix #979
2019-06-22 13:56:29 +08:00
AllenFang
31724fec7f add story for #979 2019-06-22 13:51:04 +08:00
AllenFang
4cf6e65abc fix #979 2019-06-22 13:50:50 +08:00
AllenFang
40c5ae7459 Publish
- react-bootstrap-table2-editor@1.2.4
 - react-bootstrap-table2-example@1.0.26
 - react-bootstrap-table2-toolkit@2.0.1
 - react-bootstrap-table-next@3.1.4
2019-06-10 20:53:14 +08:00
Allen
3747c36039 Merge pull request #973 from react-bootstrap-table/develop
20190610 release
2019-06-10 20:51:10 +08:00
AllenFang
0d0d1a8913 fix #947 2019-06-08 17:19:39 +08:00
AllenFang
db612eaa99 fix #946 2019-06-08 16:47:14 +08:00
Allen
4d76d88e9a fix #945 (#967) 2019-06-08 13:11:49 +08:00
William Laugesen
1cd31dc54c Added Prop to csv/exporter.js to allow overriding of the Blob's default type (#958) 2019-06-07 13:18:50 +08:00
Bill Parrott
4ec02b294a set tabindex to 0 for table headers; fixes #955 (#965) 2019-06-05 20:13:35 +08:00
54 changed files with 1108 additions and 86 deletions

View File

@@ -98,7 +98,14 @@ import overlayFactory from 'react-bootstrap-table2-overlay';
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`: 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`:
```js ```js
overlay={ overlayFactory({ spinner: true, background: 'rgba(192,192,192,0.3)' }) } overlay={
overlayFactory({
spinner: true,
styles: {
overlay: (base) => ({...base, background: 'rgba(255, 0, 0, 0.5)'})
}
})
}
``` ```
### <a name='caption'>caption - [String | Node]</a> ### <a name='caption'>caption - [String | Node]</a>
@@ -334,4 +341,4 @@ handleDataChange = ({ dataSize }) => {
onDataSizeChange={ handleDataChange } onDataSizeChange={ handleDataChange }
.... ....
/> />
``` ```

View File

@@ -11,6 +11,7 @@ Available properties in a column object:
* [hidden](#hidden) * [hidden](#hidden)
* [formatter](#formatter) * [formatter](#formatter)
* [formatExtraData](#formatExtraData) * [formatExtraData](#formatExtraData)
* [type](#type)
* [sort](#sort) * [sort](#sort)
* [sortFunc](#sortFunc) * [sortFunc](#sortFunc)
* [sortCaret](#sortCaret) * [sortCaret](#sortCaret)
@@ -132,6 +133,10 @@ The third argument: `components` have following specified properties:
## <a name='formatExtraData'>column.formatExtraData - [Any]</a> ## <a name='formatExtraData'>column.formatExtraData - [Any]</a>
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. 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.
## <a name='type'>column.type - [String]</a>
Specify the data type on column. Available value so far is `string`, `number`, `bool` and `date`. Default is `string`.
`column.type` can be used when you enable the cell editing and want to save your cell data with correct data type.
## <a name='sort'>column.sort - [Bool]</a> ## <a name='sort'>column.sort - [Bool]</a>
Enable the column sort via a `true` value given. Enable the column sort via a `true` value given.

View File

@@ -18,6 +18,7 @@
* [expandColumnPosition](#expandColumnPosition) * [expandColumnPosition](#expandColumnPosition)
* [expandColumnRenderer](#expandColumnRenderer) * [expandColumnRenderer](#expandColumnRenderer)
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer) * [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
* [parentClassName](#parentClassName)
### <a name="renderer">expandRow.renderer - [Function]</a> ### <a name="renderer">expandRow.renderer - [Function]</a>
@@ -25,12 +26,13 @@ Specify the content of expand row, `react-bootstrap-table2` will pass a row obje
#### values #### values
* **row** * **row**
* **rowIndex**
#### examples #### examples
```js ```js
const expandRow = { const expandRow = {
renderer: row => ( renderer: (row, rowIndex) => (
<div> <div>
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p> <p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
<p>You can render anything here, also you can add additional data on every row object</p> <p>You can render anything here, also you can add additional data on every row object</p>
@@ -165,3 +167,24 @@ const expandRow = {
expandColumnPosition: 'right' expandColumnPosition: 'right'
}; };
``` ```
### <a name='parentClassName'>expandRow.parentClassName - [String | Function]</a>
Apply the custom class name on parent row of expanded row. For example:
```js
const expandRow = {
renderer: (row) => ...,
parentClassName: 'foo'
};
```
Below case is more flexible way to custom the class name:
```js
const expandRow = {
renderer: (row) => ...,
parentClassName: (isExpanded, row, rowIndex) => {
if (rowIndex > 2) return 'foo';
return 'bar';
}
};
```

View File

@@ -16,11 +16,13 @@
* [clickToEdit](#clickToEdit) * [clickToEdit](#clickToEdit)
* [onSelect](#onSelect) * [onSelect](#onSelect)
* [onSelectAll](#onSelectAll) * [onSelectAll](#onSelectAll)
* [selectColumnPosition](#selectColumnPosition)
* [hideSelectColumn](#hideSelectColumn) * [hideSelectColumn](#hideSelectColumn)
* [hideSelectAll](#hideSelectAll) * [hideSelectAll](#hideSelectAll)
* [selectionRenderer](#selectionRenderer) * [selectionRenderer](#selectionRenderer)
* [selectionHeaderRenderer](#selectionHeaderRenderer) * [selectionHeaderRenderer](#selectionHeaderRenderer)
* [headerColumnStyle](#headerColumnStyle) * [headerColumnStyle](#headerColumnStyle)
* [selectColumnStyle](#selectColumnStyle)
### <a name="mode">selectRow.mode - [String]</a> ### <a name="mode">selectRow.mode - [String]</a>
@@ -224,6 +226,42 @@ const selectRow = {
}; };
``` ```
### <a name='selectColumnStyle'>selectRow.selectColumnStyle - [Object | Function]</a>
A way to custome the selection cell. `selectColumnStyle` not only accept a simple style object but also a callback function for more flexible customization:
### Style Object
```js
const selectRow = {
mode: 'checkbox',
selectColumnStyle: { backgroundColor: 'blue' }
};
```
### Callback Function
If a callback function present, you can get below information to custom the selection cell:
* `checked`: Whether current row is seleccted or not
* `disabled`: Whether current row is disabled or not
* `rowIndex`: Current row index
* `rowKey`: Current row key
```js
const selectRow = {
mode: 'checkbox',
selectColumnStyle: ({
checked,
disabled,
rowIndex,
rowKey
}) => (
// ....
return { backgroundColor: 'blue' };
)
};
```
### <a name='onSelect'>selectRow.onSelect - [Function]</a> ### <a name='onSelect'>selectRow.onSelect - [Function]</a>
This callback function will be called when a row is select/unselect and pass following three arguments: This callback function will be called when a row is select/unselect and pass following three arguments:
`row`, `isSelect`, `rowIndex` and `e`. `row`, `isSelect`, `rowIndex` and `e`.
@@ -275,6 +313,16 @@ const selectRow = {
}; };
``` ```
### <a name='selectColumnPosition'>selectRow.selectColumnPosition - [String]</a>
Default is `left`. You can give this as `right` for rendering selection column in the right side.
```js
const selectRow = {
mode: 'checkbox',
selectColumnPosition: 'right'
};
```
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a> ### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
Default is `false`, if you don't want to have a selection column, give this prop as `true` Default is `false`, if you don't want to have a selection column, give this prop as `true`

View File

@@ -89,7 +89,10 @@ const columns = [
In the following, we go though all the predefined editors: In the following, we go though all the predefined editors:
### Dropdown Editor ### Dropdown Editor
Dropdown editor give a select menu to choose a data from a list, the `editor.options` is required property for dropdown editor. Dropdown editor give a select menu to choose a data from a list. When use dropdown editor, either `editor.options` or `editor.getOptions` should be required prop.
#### editor.options
This is most simple case for assign the dropdown options data directly.
```js ```js
import { Type } from 'react-bootstrap-table2-editor'; import { Type } from 'react-bootstrap-table2-editor';
@@ -119,6 +122,46 @@ const columns = [
}]; }];
``` ```
#### editor.getOptions
It is much flexible which accept a function and you can assign the dropdown options dynamically.
There are two case for `getOptions`:
* *Synchronous*: Just return the options array in `getOptions` callback function
* *Asynchronous*: Call `setOptions` function argument when you get the options from remote.
```js
// Synchronous
const columns = [
..., {
dataField: 'type',
text: 'Job Type',
editor: {
type: Type.SELECT,
getOptions: () => [.....]
}
}];
// Asynchronous
const columns = [
..., {
dataField: 'type',
text: 'Job Type',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
setTimeout(() => setOptions([...]), 1500);
}
}
}];
```
[here](https://react-bootstrap-table.github.io/react-bootstrap-table2/storybook/index.html?selectedKind=Cell%20Editing&selectedStory=Dropdown%20Editor%20with%20Dynamic%20Options) is an online example.
### Date Editor ### Date Editor
Date editor is use `<input type="date">`, the configuration is very simple: Date editor is use `<input type="date">`, the configuration is very simple:

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table2-editor", "name": "react-bootstrap-table2-editor",
"version": "1.2.3", "version": "1.3.1",
"description": "it's the editor addon for react-bootstrap-table2", "description": "it's the editor addon for react-bootstrap-table2",
"main": "./lib/index.js", "main": "./lib/index.js",
"scripts": { "scripts": {

View File

@@ -56,12 +56,13 @@ export default (
} }
handleCellUpdate(row, column, newValue) { handleCellUpdate(row, column, newValue) {
const newValueWithType = dataOperator.typeConvert(column.type, newValue);
const { cellEdit } = this.props; const { cellEdit } = this.props;
const { beforeSaveCell } = cellEdit.options; const { beforeSaveCell } = cellEdit.options;
const oldValue = _.get(row, column.dataField); const oldValue = _.get(row, column.dataField);
const beforeSaveCellDone = (result = true) => { const beforeSaveCellDone = (result = true) => {
if (result) { if (result) {
this.doUpdate(row, column, newValue); this.doUpdate(row, column, newValueWithType);
} else { } else {
this.escapeEditing(); this.escapeEditing();
} }
@@ -69,7 +70,7 @@ export default (
if (_.isFunction(beforeSaveCell)) { if (_.isFunction(beforeSaveCell)) {
const result = beforeSaveCell( const result = beforeSaveCell(
oldValue, oldValue,
newValue, newValueWithType,
row, row,
column, column,
beforeSaveCellDone beforeSaveCellDone
@@ -78,7 +79,7 @@ export default (
return; return;
} }
} }
this.doUpdate(row, column, newValue); this.doUpdate(row, column, newValueWithType);
} }
doUpdate(row, column, newValue) { doUpdate(row, column, newValue) {

View File

@@ -4,6 +4,15 @@ import cs from 'classnames';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
class DropDownEditor extends Component { class DropDownEditor extends Component {
constructor(props) {
super(props);
let options = props.options;
if (props.getOptions) {
options = props.getOptions(this.setOptions.bind(this)) || [];
}
this.state = { options };
}
componentDidMount() { componentDidMount() {
const { defaultValue, didMount } = this.props; const { defaultValue, didMount } = this.props;
this.select.value = defaultValue; this.select.value = defaultValue;
@@ -11,12 +20,16 @@ class DropDownEditor extends Component {
if (didMount) didMount(); if (didMount) didMount();
} }
setOptions(options) {
this.setState({ options });
}
getValue() { getValue() {
return this.select.value; return this.select.value;
} }
render() { render() {
const { defaultValue, didMount, className, options, ...rest } = this.props; const { defaultValue, didMount, getOptions, className, ...rest } = this.props;
const editorClass = cs('form-control editor edit-select', className); const editorClass = cs('form-control editor edit-select', className);
const attr = { const attr = {
@@ -31,7 +44,7 @@ class DropDownEditor extends Component {
defaultValue={ defaultValue } defaultValue={ defaultValue }
> >
{ {
options.map(({ label, value }) => ( this.state.options.map(({ label, value }) => (
<option key={ value } value={ value }>{ label }</option> <option key={ value } value={ value }>{ label }</option>
)) ))
} }
@@ -52,13 +65,16 @@ DropDownEditor.propTypes = {
label: PropTypes.string, label: PropTypes.string,
value: PropTypes.any value: PropTypes.any
})) }))
]).isRequired, ]),
didMount: PropTypes.func didMount: PropTypes.func,
getOptions: PropTypes.func
}; };
DropDownEditor.defaultProps = { DropDownEditor.defaultProps = {
className: '', className: '',
defaultValue: '', defaultValue: '',
style: {}, style: {},
didMount: undefined options: [],
didMount: undefined,
getOptions: undefined
}; };
export default DropDownEditor; export default DropDownEditor;

View File

@@ -0,0 +1,123 @@
/* eslint prefer-template: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
import Code from 'components/common/code-block';
import { stockGenerator } from 'utils/common';
const products = stockGenerator();
const columns = [{
dataField: 'id',
text: 'Stock ID'
}, {
dataField: 'name',
text: 'Stock Name'
}, {
dataField: 'price',
text: 'Price',
type: 'number'
}, {
dataField: 'visible',
text: 'Visible?',
type: 'bool',
editor: {
type: Type.CHECKBOX,
value: 'true:false'
}
}, {
dataField: 'inStockDate',
text: 'Stock Date',
type: 'date',
formatter: (cell) => {
let dateObj = cell;
if (typeof cell !== 'object') {
dateObj = new Date(cell);
}
return `${('0' + dateObj.getUTCDate()).slice(-2)}/${('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/${dateObj.getUTCFullYear()}`;
},
editor: {
type: Type.DATE
}
}];
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
import cellEditFactory from 'react-bootstrap-table2-editor';
const columns = [{
dataField: 'id',
text: 'Stock ID'
}, {
dataField: 'name',
text: 'Stock Name'
}, {
dataField: 'price',
text: 'Price',
type: 'number'
}, {
dataField: 'visible',
text: 'Visible?',
type: 'bool',
editor: {
type: Type.CHECKBOX,
value: 'true:false'
}
}, {
dataField: 'inStockDate',
text: 'Stock Date',
type: 'date',
formatter: (cell) => {
let dateObj = cell;
if (typeof cell !== 'object') {
dateObj = new Date(cell);
}
return \`$\{('0' + dateObj.getUTCDate()).slice(-2)}/$\{('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/$\{dateObj.getUTCFullYear()}\`;
},
editor: {
type: Type.DATE
}
}];
function afterSaveCell(oldValue, newValue) {
console.log('--after save cell--');
console.log('New Value was apply as');
console.log(newValue);
console.log(\`and the type is $\{typeof newValue}\`);
}
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
cellEdit={ cellEditFactory({
mode: 'click',
blurToSave: true,
afterSaveCell
}) }
/>
`;
function afterSaveCell(oldValue, newValue) {
console.log('--after save cell--');
console.log('New Value was apply as');
console.log(newValue);
console.log(`and the type is ${typeof newValue}`);
}
export default () => (
<div>
<h3>Save Cell Value with Specified Data Type</h3>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
cellEdit={ cellEditFactory({
mode: 'click',
blurToSave: true,
afterSaveCell
}) }
/>
<Code>{ sourceCode }</Code>
</div>
);

View File

@@ -0,0 +1,155 @@
/* eslint react/prefer-stateless-function: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
import Code from 'components/common/code-block';
import { jobsGenerator } from 'utils/common';
const jobs = jobsGenerator().map(j => ({
...j,
type2: j.type
}));
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name'
}, {
dataField: 'owner',
text: 'Job Owner'
}, {
dataField: 'type',
text: 'Job Type1',
editor: {
type: Type.SELECT,
getOptions: () => [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
}
}, {
dataField: 'type2',
text: 'Job Type2',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
setTimeout(() => {
setOptions([{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]);
}, 2000);
}
}
}];
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name'
}, {
dataField: 'owner',
text: 'Job Owner'
}, {
dataField: 'type',
text: 'Job Type1',
editor: {
type: Type.SELECT,
getOptions: () => [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
}
}, {
dataField: 'type2',
text: 'Job Type2',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
setTimeout(() => {
setOptions([{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]);
}, 2000);
}
}
}];
<BootstrapTable
keyField="id"
data={ jobs }
columns={ columns }
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
/>
`;
export default () => (
<div>
<h3>Dropdown Editor with Dynamic Options</h3>
<BootstrapTable
keyField="id"
data={ jobs }
columns={ columns }
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
/>
<Code>{ sourceCode }</Code>
</div>
);

View File

@@ -12,8 +12,12 @@ import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
class Table extends React.Component { class Table extends React.Component {
filterByPrice = filterVal => filterByPrice = (filterVal) => {
products.filter(product => product.price == filterVal); if (filterVal) {
return products.filter(product => product.price == filterVal);
}
return products;
}
render() { render() {
const columns = [{ const columns = [{
@@ -46,8 +50,12 @@ class Table extends React.Component {
`; `;
export default class Table extends React.Component { export default class Table extends React.Component {
filterByPrice = filterVal => filterByPrice = (filterVal) => {
products.filter(product => product.price == filterVal); if (filterVal) {
return products.filter(product => product.price == filterVal);
}
return products;
}
render() { render() {
const columns = [{ const columns = [{
@@ -67,7 +75,7 @@ export default class Table extends React.Component {
return ( return (
<div> <div>
<h2>Implement a eq filter on product price column</h2> <h2>Implement Custom Filter</h2>
<BootstrapTable <BootstrapTable
keyField="id" keyField="id"
data={ products } data={ products }

View File

@@ -0,0 +1,188 @@
/* eslint no-param-reassign: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = productsGenerator();
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
class DummyColumnWithRowExpand extends React.Component {
constructor(props) {
super(props);
this.state = {
hoverIdx: null
};
}
expandRow = {
renderer: () => (
<div style={ { width: '100%', height: '20px' } }>Content</div>
),
showExpandColumn: true,
expandByColumnOnly: true
};
actionFormater = (cell, row, rowIndex, { hoverIdx }) => {
if ((hoverIdx !== null || hoverIdx !== undefined) && hoverIdx === rowIndex) {
return (
<div
style={ { width: '20px', height: '20px', backgroundColor: 'orange' } }
/>
);
}
return (
<div
style={ { width: '20px', height: '20px' } }
/>
);
}
rowEvents = {
onMouseEnter: (e, row, rowIndex) => {
this.setState({ hoverIdx: rowIndex });
},
onMouseLeave: () => {
this.setState({ hoverIdx: null });
}
}
rowStyle = (row, rowIndex) => {
row.index = rowIndex;
const style = {};
if (rowIndex % 2 === 0) {
style.backgroundColor = 'transparent';
} else {
style.backgroundColor = 'rgba(54, 163, 173, .10)';
}
style.borderTop = 'none';
return style;
}
render() {
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}, {
text: '',
isDummyField: true,
formatter: this.actionFormater,
formatExtraData: { hoverIdx: this.state.hoverIdx },
headerStyle: { width: '50px' },
style: { height: '30px' }
}];
return (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
noDataIndication="There is no data"
classes="table"
rowStyle={ this.rowStyle }
rowEvents={ this.rowEvents }
expandRow={ this.expandRow }
/>
</div>
);
}
}
`;
export default class DummyColumnWithRowExpand extends React.Component {
constructor(props) {
super(props);
this.state = {
hoverIdx: null
};
}
expandRow = {
renderer: () => (
<div style={ { width: '100%', height: '20px' } }>Content</div>
),
showExpandColumn: true,
expandByColumnOnly: true
};
actionFormater = (cell, row, rowIndex, { hoverIdx }) => {
if ((hoverIdx !== null || hoverIdx !== undefined) && hoverIdx === rowIndex) {
return (
<div
style={ { width: '20px', height: '20px', backgroundColor: 'orange' } }
/>
);
}
return (
<div
style={ { width: '20px', height: '20px' } }
/>
);
}
rowEvents = {
onMouseEnter: (e, row, rowIndex) => {
this.setState({ hoverIdx: rowIndex });
},
onMouseLeave: () => {
this.setState({ hoverIdx: null });
}
}
rowStyle = (row, rowIndex) => {
row.index = rowIndex;
const style = {};
if (rowIndex % 2 === 0) {
style.backgroundColor = 'transparent';
} else {
style.backgroundColor = 'rgba(54, 163, 173, .10)';
}
style.borderTop = 'none';
return style;
}
render() {
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}, {
isDummyField: true,
text: '',
formatter: this.actionFormater,
formatExtraData: { hoverIdx: this.state.hoverIdx },
headerStyle: { width: '50px' },
style: { height: '30px' }
}];
return (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
rowStyle={ this.rowStyle }
rowEvents={ this.rowEvents }
expandRow={ this.expandRow }
/>
<Code>{ sourceCode }</Code>
</div>
);
}
}

View File

@@ -36,7 +36,7 @@ const RemotePagination = ({ loading, data, page, sizePerPage, onTableChange, tot
columns={ columns } columns={ columns }
pagination={ paginationFactory({ page, sizePerPage, totalSize }) } pagination={ paginationFactory({ page, sizePerPage, totalSize }) }
onTableChange={ onTableChange } onTableChange={ onTableChange }
overlay={ overlayFactory({ spinner: true, background: 'rgba(192,192,192,0.3)' }) } overlay={ overlayFactory({ spinner: true, styles: { overlay: (base) => ({...base, background: 'rgba(255, 0, 0, 0.5)'}) } }) }
/> />
<Code>{ sourceCode }</Code> <Code>{ sourceCode }</Code>
</div> </div>
@@ -101,7 +101,12 @@ const RemotePagination = ({ loading, data, page, sizePerPage, onTableChange, tot
columns={ columns } columns={ columns }
pagination={ paginationFactory({ page, sizePerPage, totalSize }) } pagination={ paginationFactory({ page, sizePerPage, totalSize }) }
onTableChange={ onTableChange } onTableChange={ onTableChange }
overlay={ overlayFactory({ spinner: true, background: 'rgba(192,192,192,0.3)' }) } overlay={
overlayFactory({
spinner: true,
styles: { overlay: base => ({ ...base, background: 'rgba(255, 0, 0, 0.5)' }) }
})
}
/> />
<Code>{ sourceCode }</Code> <Code>{ sourceCode }</Code>
</div> </div>

View File

@@ -74,7 +74,7 @@ const options = {
// hidePageListOnlyOnePage: true, // Hide the pagination list when only one page // hidePageListOnlyOnePage: true, // Hide the pagination list when only one page
firstPageText: 'First', firstPageText: 'First',
prePageText: 'Back', prePageText: 'Back',
nextPageText: 'Next', nextPageText: <span>Next</span>,
lastPageText: 'Last', lastPageText: 'Last',
nextPageTitle: 'First page', nextPageTitle: 'First page',
prePageTitle: 'Pre page', prePageTitle: 'Pre page',

View File

@@ -18,9 +18,9 @@ const columns = [{
}]; }];
const expandRow = { const expandRow = {
renderer: row => ( renderer: (row, rowIndex) => (
<div> <div>
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p> <p>{ `This Expand row is belong to rowKey ${row.id} and index: ${rowIndex}` }</p>
<p>You can render anything here, also you can add additional data on every row object</p> <p>You can render anything here, also you can add additional data on every row object</p>
<p>expandRow.renderer callback will pass the origin row object to you</p> <p>expandRow.renderer callback will pass the origin row object to you</p>
</div> </div>

View File

@@ -0,0 +1,106 @@
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsExpandRowsGenerator } from 'utils/common';
const products = productsExpandRowsGenerator();
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const expandRow1 = {
parentClassName: 'parent-expand-foo',
renderer: row => (
<div>
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
<p>You can render anything here, also you can add additional data on every row object</p>
<p>expandRow.renderer callback will pass the origin row object to you</p>
</div>
)
};
const expandRow2 = {
parentClassName: (isExpanded, row, rowIndex) => {
if (rowIndex > 2) return 'parent-expand-foo';
return 'parent-expand-bar';
},
renderer: row => (
<div>
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
<p>You can render anything here, also you can add additional data on every row object</p>
<p>expandRow.renderer callback will pass the origin row object to you</p>
</div>
)
};
const sourceCode1 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = // omit...
const expandRow = {
parentClassName: 'parent-expand-foo',
renderer: row => (
<div>.....</div>
)
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
expandRow={ expandRow }
/>
`;
const sourceCode2 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = // omit...
const expandRow = {
parentClassName: (isExpanded, row, rowIndex) => {
if (rowIndex > 2) return 'parent-expand-foo';
return 'parent-expand-bar';
},
renderer: row => (
<div>...</div>
)
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
expandRow={ expandRow }
/>
`;
export default () => (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
expandRow={ expandRow1 }
/>
<Code>{ sourceCode1 }</Code>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
expandRow={ expandRow2 }
/>
<Code>{ sourceCode2 }</Code>
</div>
);

View File

@@ -0,0 +1,110 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = productsGenerator(2);
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow1 = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: {
backgroundColor: 'grey'
}
};
const sourceCode1 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = ...
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: {
backgroundColor: 'grey'
}
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
selectRow={ selectRow }
/>
`;
const selectRow2 = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: ({
checked,
disabled,
rowIndex,
rowKey
}) => {
if (checked) {
return {
backgroundColor: 'yellow'
};
}
return {
backgroundColor: 'pink'
};
}
};
const sourceCode2 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = ...
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: ({
checked,
disabled,
rowIndex,
rowKey
}) => {
if (checked) {
return {
backgroundColor: 'yellow'
};
}
return {
backgroundColor: 'pink'
};
}
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
selectRow={ selectRow }
/>
`;
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow1 } />
<Code>{ sourceCode1 }</Code>
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow2 } />
<Code>{ sourceCode2 }</Code>
</div>
);

View File

@@ -0,0 +1,59 @@
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = productsGenerator();
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnPosition: 'right'
};
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnPosition: 'right'
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
selectRow={ selectRow }
/>
`;
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
<Code>{ sourceCode }</Code>
</div>
);

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table2-example", "name": "react-bootstrap-table2-example",
"version": "1.0.25", "version": "1.0.28",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"private": true, "private": true,

View File

@@ -69,8 +69,9 @@ const endDate = new Date();
export const stockGenerator = (quantity = 5) => export const stockGenerator = (quantity = 5) =>
Array.from({ length: quantity }, (value, index) => ({ Array.from({ length: quantity }, (value, index) => ({
id: index, id: index,
name: `Todo item ${index}`, name: `Stock Name ${index}`,
price: Math.floor((Math.random() * 2) + 1), price: Math.floor((Math.random() * 2) + 1),
visible: Math.random() > 0.5,
inStockDate: inStockDate:
new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime())) new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()))
})); }));

View File

@@ -35,6 +35,7 @@ import ColumnEventTable from 'examples/columns/column-event-table';
import ColumnHiddenTable from 'examples/columns/column-hidden-table'; import ColumnHiddenTable from 'examples/columns/column-hidden-table';
import ColumnAttrsTable from 'examples/columns/column-attrs-table'; import ColumnAttrsTable from 'examples/columns/column-attrs-table';
import DummyColumnTable from 'examples/columns/dummy-column-table'; import DummyColumnTable from 'examples/columns/dummy-column-table';
import RowExpandWithFormattedDummyColumn from 'examples/columns/row-expand-with-formatted-dummy-column.js';
// work on header columns // work on header columns
import HeaderColumnFormatTable from 'examples/header-columns/column-format-table'; import HeaderColumnFormatTable from 'examples/header-columns/column-format-table';
@@ -125,10 +126,12 @@ import EditorStyleTable from 'examples/cell-edit/editor-style-table';
import EditorClassTable from 'examples/cell-edit/editor-class-table'; import EditorClassTable from 'examples/cell-edit/editor-class-table';
import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table'; import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table';
import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table'; import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table';
import DropdownEditorWithDynamicOptionsTable from 'examples/cell-edit/dropdown-editor-with-dynamic-options-table';
import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table'; import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table';
import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table'; import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table';
import DateEditorTable from 'examples/cell-edit/date-editor-table'; import DateEditorTable from 'examples/cell-edit/date-editor-table';
import CustomEditorTable from 'examples/cell-edit/custom-editor-table'; import CustomEditorTable from 'examples/cell-edit/custom-editor-table';
import CellEditorWithDataType from 'examples/cell-edit/cell-edit-with-data-type';
// work on row selection // work on row selection
import SingleSelectionTable from 'examples/row-selection/single-selection'; import SingleSelectionTable from 'examples/row-selection/single-selection';
@@ -149,6 +152,8 @@ import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor'; import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
import SelectionHooks from 'examples/row-selection/selection-hooks'; import SelectionHooks from 'examples/row-selection/selection-hooks';
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column'; import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
import SelectionColumnStyleTable from 'examples/row-selection/select-column-style';
import SelectionColumnPositionTable from 'examples/row-selection/selection-column-position';
// work on row expand // work on row expand
import BasicRowExpand from 'examples/row-expand'; import BasicRowExpand from 'examples/row-expand';
@@ -160,6 +165,7 @@ import ExpandOnlyOne from 'examples/row-expand/expand-only-one';
import CustomExpandColumn from 'examples/row-expand/custom-expand-column'; import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
import ExpandColumnPosition from 'examples/row-expand/expand-column-position'; import ExpandColumnPosition from 'examples/row-expand/expand-column-position';
import ExpandHooks from 'examples/row-expand/expand-hooks'; import ExpandHooks from 'examples/row-expand/expand-hooks';
import ParentRowClassName from 'examples/row-expand/parent-row-classname';
// pagination // pagination
import PaginationTable from 'examples/pagination'; import PaginationTable from 'examples/pagination';
@@ -270,7 +276,8 @@ storiesOf('Work on Columns', module)
.add('Customize Column Class', () => <ColumnClassTable />) .add('Customize Column Class', () => <ColumnClassTable />)
.add('Customize Column Style', () => <ColumnStyleTable />) .add('Customize Column Style', () => <ColumnStyleTable />)
.add('Customize Column HTML attribute', () => <ColumnAttrsTable />) .add('Customize Column HTML attribute', () => <ColumnAttrsTable />)
.add('Dummy Column', () => <DummyColumnTable />); .add('Dummy Column', () => <DummyColumnTable />)
.add('Row Expand with Dummy Column Formatter', () => <RowExpandWithFormattedDummyColumn />);
storiesOf('Work on Header Columns', module) storiesOf('Work on Header Columns', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())
@@ -368,10 +375,12 @@ storiesOf('Cell Editing', module)
.add('Custom Editor Style', () => <EditorStyleTable />) .add('Custom Editor Style', () => <EditorStyleTable />)
.add('DoubleClick to Edit with Selection', () => <DBClickEditWithSelection />) .add('DoubleClick to Edit with Selection', () => <DBClickEditWithSelection />)
.add('Dropdown Editor', () => <DropdownEditorTable />) .add('Dropdown Editor', () => <DropdownEditorTable />)
.add('Dropdown Editor with Dynamic Options', () => <DropdownEditorWithDynamicOptionsTable />)
.add('Textarea Editor', () => <TextareaEditorTable />) .add('Textarea Editor', () => <TextareaEditorTable />)
.add('Checkbox Editor', () => <CheckboxEditorTable />) .add('Checkbox Editor', () => <CheckboxEditorTable />)
.add('Date Editor', () => <DateEditorTable />) .add('Date Editor', () => <DateEditorTable />)
.add('Custom Editor', () => <CustomEditorTable />); .add('Custom Editor', () => <CustomEditorTable />)
.add('Cell Editor with Data Type', () => <CellEditorWithDataType />);
storiesOf('Row Selection', module) storiesOf('Row Selection', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())
@@ -392,7 +401,9 @@ storiesOf('Row Selection', module)
.add('Selection Background Color', () => <SelectionBgColorTable />) .add('Selection Background Color', () => <SelectionBgColorTable />)
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />) .add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
.add('Selection Hooks', () => <SelectionHooks />) .add('Selection Hooks', () => <SelectionHooks />)
.add('Hide Selection Column', () => <HideSelectionColumnTable />); .add('Hide Selection Column', () => <HideSelectionColumnTable />)
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
.add('Selection Column Position', () => <SelectionColumnPositionTable />);
storiesOf('Row Expand', module) storiesOf('Row Expand', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())
@@ -404,7 +415,8 @@ storiesOf('Row Expand', module)
.add('Expand Only One Row at The Same Time', () => <ExpandOnlyOne />) .add('Expand Only One Row at The Same Time', () => <ExpandOnlyOne />)
.add('Custom Expand Indicator', () => <CustomExpandColumn />) .add('Custom Expand Indicator', () => <CustomExpandColumn />)
.add('Expand Column Position', () => <ExpandColumnPosition />) .add('Expand Column Position', () => <ExpandColumnPosition />)
.add('Expand Hooks', () => <ExpandHooks />); .add('Expand Hooks', () => <ExpandHooks />)
.add('Custom Parent Row ClassName', () => <ParentRowClassName />);
storiesOf('Pagination', module) storiesOf('Pagination', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())

View File

@@ -0,0 +1,7 @@
.parent-expand-foo {
background-color: coral;
}
.parent-expand-bar {
background-color: aqua;
}

View File

@@ -12,3 +12,4 @@
@import "sort/index"; @import "sort/index";
@import "search/index"; @import "search/index";
@import "loading-overlay/index"; @import "loading-overlay/index";
@import "row-expand/index";

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table2-filter", "name": "react-bootstrap-table2-filter",
"version": "1.1.9", "version": "1.1.10",
"description": "it's a column filter addon for react-bootstrap-table2", "description": "it's a column filter addon for react-bootstrap-table2",
"main": "./lib/index.js", "main": "./lib/index.js",
"repository": { "repository": {

View File

@@ -18,8 +18,18 @@ function optionsEquals(currOpts, prevOpts) {
return Object.keys(currOpts).length === Object.keys(prevOpts).length; return Object.keys(currOpts).length === Object.keys(prevOpts).length;
} }
const getSelections = container => const getSelections = (container) => {
Array.from(container.selectedOptions).map(item => item.value); if (container.selectedOptions) {
return Array.from(container.selectedOptions).map(item => item.value);
}
const selections = [];
const totalLen = container.options.length;
for (let i = 0; i < totalLen; i += 1) {
const option = container.options.item(i);
if (option.selected) selections.push(option.value);
}
return selections;
};
class MultiSelectFilter extends Component { class MultiSelectFilter extends Component {
constructor(props) { constructor(props) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table2-paginator", "name": "react-bootstrap-table2-paginator",
"version": "2.0.6", "version": "2.0.7",
"description": "it's the pagination addon for react-bootstrap-table2", "description": "it's the pagination addon for react-bootstrap-table2",
"main": "./lib/index.js", "main": "./lib/index.js",
"repository": { "repository": {

View File

@@ -39,7 +39,11 @@ class PageButton extends Component {
PageButton.propTypes = { PageButton.propTypes = {
onPageChange: PropTypes.func.isRequired, onPageChange: PropTypes.func.isRequired,
page: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, page: PropTypes.oneOfType([
PropTypes.node,
PropTypes.number,
PropTypes.string
]).isRequired,
active: PropTypes.bool.isRequired, active: PropTypes.bool.isRequired,
disabled: PropTypes.bool.isRequired, disabled: PropTypes.bool.isRequired,
className: PropTypes.string, className: PropTypes.string,

View File

@@ -27,7 +27,11 @@ const PaginatonList = props => (
PaginatonList.propTypes = { PaginatonList.propTypes = {
pages: PropTypes.arrayOf(PropTypes.shape({ pages: PropTypes.arrayOf(PropTypes.shape({
page: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), page: PropTypes.oneOfType([
PropTypes.node,
PropTypes.number,
PropTypes.string
]),
active: PropTypes.bool, active: PropTypes.bool,
disable: PropTypes.bool, disable: PropTypes.bool,
title: PropTypes.string title: PropTypes.string

View File

@@ -100,10 +100,10 @@ Pagination.propTypes = {
sizePerPageRenderer: PropTypes.func, sizePerPageRenderer: PropTypes.func,
paginationTotalRenderer: PropTypes.func, paginationTotalRenderer: PropTypes.func,
sizePerPageOptionRenderer: PropTypes.func, sizePerPageOptionRenderer: PropTypes.func,
firstPageText: PropTypes.string, firstPageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
prePageText: PropTypes.string, prePageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
nextPageText: PropTypes.string, nextPageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
lastPageText: PropTypes.string, lastPageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
nextPageTitle: PropTypes.string, nextPageTitle: PropTypes.string,
prePageTitle: PropTypes.string, prePageTitle: PropTypes.string,
firstPageTitle: PropTypes.string, firstPageTitle: PropTypes.string,

View File

@@ -185,6 +185,9 @@ Default is `false`. Give true to avoid to attach the csv header.
#### noAutoBOM - [bool] #### noAutoBOM - [bool]
Default is `true`. Default is `true`.
#### blobType - [string]
Default is `text/plain;charset=utf-8`. Change to update the blob type of the exported file.
#### exportAll - [bool] #### exportAll - [bool]
Default is `true`. `false` will only export current data which display on table. Default is `true`. `false` will only export current data which display on table.

View File

@@ -29,6 +29,7 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
separator: PropTypes.string, separator: PropTypes.string,
ignoreHeader: PropTypes.bool, ignoreHeader: PropTypes.bool,
noAutoBOM: PropTypes.bool, noAutoBOM: PropTypes.bool,
blobType: PropTypes.string,
exportAll: PropTypes.bool, exportAll: PropTypes.bool,
onlyExportFiltered: PropTypes.bool, onlyExportFiltered: PropTypes.bool,
onlyExportSelection: PropTypes.bool onlyExportSelection: PropTypes.bool

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table2-toolkit", "name": "react-bootstrap-table2-toolkit",
"version": "2.0.0", "version": "2.0.1",
"description": "The toolkit for react-bootstrap-table2", "description": "The toolkit for react-bootstrap-table2",
"main": "./lib/index.js", "main": "./lib/index.js",
"repository": { "repository": {

View File

@@ -54,11 +54,12 @@ export const save = (
content, content,
{ {
noAutoBOM, noAutoBOM,
fileName fileName,
blobType
} }
) => { ) => {
FileSaver.saveAs( FileSaver.saveAs(
new Blob([content], { type: 'text/plain;charset=utf-8' }), new Blob([content], { type: blobType }),
fileName, fileName,
noAutoBOM noAutoBOM
); );

View File

@@ -5,6 +5,7 @@ const csvDefaultOptions = {
separator: ',', separator: ',',
ignoreHeader: false, ignoreHeader: false,
noAutoBOM: true, noAutoBOM: true,
blobType: 'text/plain;charset=utf-8',
exportAll: true, exportAll: true,
onlyExportSelection: false onlyExportSelection: false
}; };

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table-next", "name": "react-bootstrap-table-next",
"version": "3.1.3", "version": "3.1.7",
"description": "Next generation of react-bootstrap-table", "description": "Next generation of react-bootstrap-table",
"main": "./lib/index.js", "main": "./lib/index.js",
"repository": { "repository": {

View File

@@ -168,7 +168,12 @@ BootstrapTable.propTypes = {
hideSelectColumn: PropTypes.bool, hideSelectColumn: PropTypes.bool,
selectionRenderer: PropTypes.func, selectionRenderer: PropTypes.func,
selectionHeaderRenderer: PropTypes.func, selectionHeaderRenderer: PropTypes.func,
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]) headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
selectColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
selectColumnPosition: PropTypes.oneOf([
Const.INDICATOR_POSITION_LEFT,
Const.INDICATOR_POSITION_RIGHT
])
}), }),
expandRow: PropTypes.shape({ expandRow: PropTypes.shape({
renderer: PropTypes.func, renderer: PropTypes.func,
@@ -184,7 +189,8 @@ BootstrapTable.propTypes = {
expandColumnPosition: PropTypes.oneOf([ expandColumnPosition: PropTypes.oneOf([
Const.INDICATOR_POSITION_LEFT, Const.INDICATOR_POSITION_LEFT,
Const.INDICATOR_POSITION_RIGHT Const.INDICATOR_POSITION_RIGHT
]) ]),
parentClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
}), }),
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
rowEvents: PropTypes.object, rowEvents: PropTypes.object,

View File

@@ -1,3 +1,5 @@
import _ from './utils';
const events = [ const events = [
'onClick', 'onClick',
'onDoubleClick', 'onDoubleClick',
@@ -23,7 +25,7 @@ export default ExtendBase =>
delegate(attrs = {}) { delegate(attrs = {}) {
const newAttrs = { ...attrs }; const newAttrs = { ...attrs };
Object.keys(attrs).forEach((attr) => { Object.keys(attrs).forEach((attr) => {
if (events.includes(attr)) { if (_.contains(events, attr)) {
newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]); newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]);
} }
}); });

View File

@@ -8,5 +8,9 @@ export default {
CHECKBOX_STATUS_INDETERMINATE: 'indeterminate', CHECKBOX_STATUS_INDETERMINATE: 'indeterminate',
CHECKBOX_STATUS_UNCHECKED: 'unchecked', CHECKBOX_STATUS_UNCHECKED: 'unchecked',
INDICATOR_POSITION_LEFT: 'left', INDICATOR_POSITION_LEFT: 'left',
INDICATOR_POSITION_RIGHT: 'right' INDICATOR_POSITION_RIGHT: 'right',
TYPE_STRING: 'string',
TYPE_NUMBER: 'number',
TYPE_BOOLEAN: 'bool',
TYPE_DATE: 'date'
}; };

View File

@@ -20,7 +20,7 @@ class RowExpandProvider extends React.Component {
if (nextProps.expandRow) { if (nextProps.expandRow) {
const nextExpanded = nextProps.expandRow.expanded || this.state.expanded; const nextExpanded = nextProps.expandRow.expanded || this.state.expanded;
const isClosing = this.state.expanded.reduce((acc, cur) => { const isClosing = this.state.expanded.reduce((acc, cur) => {
if (!nextExpanded.includes(cur)) { if (!_.contains(nextExpanded, cur)) {
acc.push(cur); acc.push(cur);
} }
return acc; return acc;
@@ -42,7 +42,7 @@ class RowExpandProvider extends React.Component {
handleRowExpand = (rowKey, expanded, rowIndex, e) => { handleRowExpand = (rowKey, expanded, rowIndex, e) => {
const { data, keyField, expandRow: { onExpand, onlyOneExpanding, nonExpandable } } = this.props; const { data, keyField, expandRow: { onExpand, onlyOneExpanding, nonExpandable } } = this.props;
if (nonExpandable && nonExpandable.includes(rowKey)) { if (nonExpandable && _.contains(nonExpandable, rowKey)) {
return; return;
} }

View File

@@ -11,9 +11,9 @@ const Footer = (props) => {
const SelectionFooterCellComp = () => <th />; const SelectionFooterCellComp = () => <th />;
const ExpansionFooterCellComp = () => <th />; const ExpansionFooterCellComp = () => <th />;
const isRenderExpandColumnInLeft = ( const isRenderFunctionColumnInLeft = (
expandColumnPosition = Const.INDICATOR_POSITION_LEFT position = Const.INDICATOR_POSITION_LEFT
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT; ) => position === Const.INDICATOR_POSITION_LEFT;
const childrens = columns.map((column, i) => { const childrens = columns.map((column, i) => {
if (column.footer === undefined || column.footer === null) { if (column.footer === undefined || column.footer === null) {
@@ -33,11 +33,15 @@ const Footer = (props) => {
}); });
if (selectRow && selectRow.hideSelectColumn !== true) { if (selectRow && selectRow.hideSelectColumn !== true) {
childrens.unshift(<SelectionFooterCellComp key="selection" />); if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
childrens.unshift(<SelectionFooterCellComp key="selection" />);
} else {
childrens.push(<SelectionFooterCellComp key="selection" />);
}
} }
if (expandRow.showExpandColumn) { if (expandRow.showExpandColumn) {
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) { if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
childrens.unshift(<ExpansionFooterCellComp key="expansion" />); childrens.unshift(<ExpansionFooterCellComp key="expansion" />);
} else { } else {
childrens.push(<ExpansionFooterCellComp key="expansion" />); childrens.push(<ExpansionFooterCellComp key="expansion" />);

View File

@@ -41,7 +41,7 @@ const HeaderCell = (props) => {
const cellAttrs = { const cellAttrs = {
..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs, ..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs,
...headerEvents, ...headerEvents,
tabIndex: index + 1 tabIndex: 0
}; };
let sortSymbol; let sortSymbol;
@@ -117,6 +117,12 @@ HeaderCell.propTypes = {
column: PropTypes.shape({ column: PropTypes.shape({
dataField: PropTypes.string.isRequired, dataField: PropTypes.string.isRequired,
text: PropTypes.string.isRequired, text: PropTypes.string.isRequired,
type: PropTypes.oneOf([
Const.TYPE_STRING,
Const.TYPE_NUMBER,
Const.TYPE_BOOLEAN,
Const.TYPE_DATE
]),
isDummyField: PropTypes.bool, isDummyField: PropTypes.bool,
hidden: PropTypes.bool, hidden: PropTypes.bool,
headerFormatter: PropTypes.func, headerFormatter: PropTypes.func,

View File

@@ -33,9 +33,9 @@ const Header = (props) => {
SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell); SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell);
} }
const isRenderExpandColumnInLeft = ( const isRenderFunctionColumnInLeft = (
expandColumnPosition = Const.INDICATOR_POSITION_LEFT position = Const.INDICATOR_POSITION_LEFT
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT; ) => position === Const.INDICATOR_POSITION_LEFT;
const childrens = [ const childrens = [
columns.map((column, i) => { columns.map((column, i) => {
@@ -58,11 +58,15 @@ const Header = (props) => {
]; ];
if (!selectRow.hideSelectColumn) { if (!selectRow.hideSelectColumn) {
childrens.unshift(<SelectionHeaderCellComp key="selection" />); if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
childrens.unshift(<SelectionHeaderCellComp key="selection" />);
} else {
childrens.push(<SelectionHeaderCellComp key="selection" />);
}
} }
if (expandRow.showExpandColumn) { if (expandRow.showExpandColumn) {
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) { if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
childrens.unshift(<ExpansionHeaderCellComp key="expansion" />); childrens.unshift(<ExpansionHeaderCellComp key="expansion" />);
} else { } else {
childrens.push(<ExpansionHeaderCellComp key="expansion" />); childrens.push(<ExpansionHeaderCellComp key="expansion" />);

View File

@@ -22,7 +22,7 @@ export default ExtendBase =>
if (!hiddenRows || hiddenRows.length === 0) return data; if (!hiddenRows || hiddenRows.length === 0) return data;
return data.filter((row) => { return data.filter((row) => {
const key = _.get(row, keyField); const key = _.get(row, keyField);
return !hiddenRows.includes(key); return !_.contains(hiddenRows, key);
}); });
} }
}; };

View File

@@ -1,15 +1,24 @@
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import React from 'react'; import React from 'react';
import cs from 'classnames';
import ExpandRow from './expand-row'; import ExpandRow from './expand-row';
import _ from '../utils';
import ExpansionContext from '../contexts/row-expand-context'; import ExpansionContext from '../contexts/row-expand-context';
export default (Component) => { export default (Component) => {
const renderWithExpansion = (props, expandRow) => { const renderWithExpansion = (props, expandRow) => {
let parentClassName = '';
const key = props.value; const key = props.value;
const expanded = expandRow.expanded.includes(key); const expanded = _.contains(expandRow.expanded, key);
const isClosing = expandRow.isClosing.includes(key); const isClosing = _.contains(expandRow.isClosing, key);
const expandable = !expandRow.nonExpandable || !expandRow.nonExpandable.includes(key); const expandable = !expandRow.nonExpandable || !_.contains(expandRow.nonExpandable, key);
if (expanded) {
parentClassName = _.isFunction(expandRow.parentClassName) ?
expandRow.parentClassName(expanded, props.row, props.rowIndex) :
(expandRow.parentClassName || '');
}
return [ return [
<Component <Component
{ ...props } { ...props }
@@ -17,6 +26,7 @@ export default (Component) => {
expanded={ expanded } expanded={ expanded }
expandable={ expandable } expandable={ expandable }
expandRow={ { ...expandRow } } expandRow={ { ...expandRow } }
className={ cs(props.className, parentClassName) }
/>, />,
expanded || isClosing ? <ExpandRow expanded || isClosing ? <ExpandRow
key={ `${key}-expanding` } key={ `${key}-expanding` }
@@ -24,7 +34,7 @@ export default (Component) => {
expanded={ expanded } expanded={ expanded }
onClosed={ () => expandRow.onClosed(key) } onClosed={ () => expandRow.onClosed(key) }
> >
{ expandRow.renderer(props.row) } { expandRow.renderer(props.row, props.rowIndex) }
</ExpandRow> : null </ExpandRow> : null
]; ];
}; };

View File

@@ -7,8 +7,8 @@ import SelectionContext from '../contexts/selection-context';
export default (Component) => { export default (Component) => {
const renderWithSelection = (props, selectRow) => { const renderWithSelection = (props, selectRow) => {
const key = props.value; const key = props.value;
const selected = selectRow.selected.includes(key); const selected = _.contains(selectRow.selected, key);
const selectable = !selectRow.nonSelectable || !selectRow.nonSelectable.includes(key); const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
let { let {
style, style,

View File

@@ -5,6 +5,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Const from '../const'; import Const from '../const';
import _ from '../utils';
import { BootstrapContext } from '../contexts/bootstrap'; import { BootstrapContext } from '../contexts/bootstrap';
export default class SelectionCell extends Component { export default class SelectionCell extends Component {
@@ -17,7 +18,8 @@ export default class SelectionCell extends Component {
rowIndex: PropTypes.number, rowIndex: PropTypes.number,
tabIndex: PropTypes.number, tabIndex: PropTypes.number,
clickToSelect: PropTypes.bool, clickToSelect: PropTypes.bool,
selectionRenderer: PropTypes.func selectionRenderer: PropTypes.func,
selectColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
} }
constructor() { constructor() {
@@ -31,7 +33,8 @@ export default class SelectionCell extends Component {
this.props.selected !== nextProps.selected || this.props.selected !== nextProps.selected ||
this.props.disabled !== nextProps.disabled || this.props.disabled !== nextProps.disabled ||
this.props.rowKey !== nextProps.rowKey || this.props.rowKey !== nextProps.rowKey ||
this.props.tabIndex !== nextProps.tabIndex; this.props.tabIndex !== nextProps.tabIndex ||
this.props.selectColumnStyle !== nextProps.selectColumnStyle;
return shouldUpdate; return shouldUpdate;
} }
@@ -57,17 +60,28 @@ export default class SelectionCell extends Component {
render() { render() {
const { const {
rowKey,
mode: inputType, mode: inputType,
selected, selected,
disabled, disabled,
tabIndex, tabIndex,
rowIndex, rowIndex,
selectionRenderer selectionRenderer,
selectColumnStyle
} = this.props; } = this.props;
const attrs = {}; const attrs = {};
if (tabIndex !== -1) attrs.tabIndex = tabIndex; if (tabIndex !== -1) attrs.tabIndex = tabIndex;
attrs.style = _.isFunction(selectColumnStyle) ?
selectColumnStyle({
checked: selected,
disabled,
rowIndex,
rowKey
}) :
selectColumnStyle;
return ( return (
<BootstrapContext.Consumer> <BootstrapContext.Consumer>
{ {

View File

@@ -35,20 +35,21 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
this.props.expanded !== nextProps.expanded || this.props.expanded !== nextProps.expanded ||
this.props.expandable !== nextProps.expandable || this.props.expandable !== nextProps.expandable ||
this.props.selectable !== nextProps.selectable || this.props.selectable !== nextProps.selectable ||
this.props.selectRow.hideSelectColumn !== nextProps.selectRow.hideSelectColumn ||
this.shouldUpdatedBySelfProps(nextProps) this.shouldUpdatedBySelfProps(nextProps)
) { ) {
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps); this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);
return true; return true;
} }
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps); this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);
return this.shouldUpdateRowContent; return this.shouldUpdateRowContent;
} }
isRenderExpandColumnInLeft( isRenderFunctionColumnInLeft(
expandColumnPosition = Const.INDICATOR_POSITION_LEFT position = Const.INDICATOR_POSITION_LEFT
) { ) {
return expandColumnPosition === Const.INDICATOR_POSITION_LEFT; return position === Const.INDICATOR_POSITION_LEFT;
} }
render() { render() {
@@ -71,7 +72,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
...rest ...rest
} = this.props; } = this.props;
const key = _.get(row, keyField); const key = _.get(row, keyField);
const { hideSelectColumn, clickToSelect } = selectRow; const { hideSelectColumn, selectColumnPosition, clickToSelect } = selectRow;
const { showExpandColumn, expandColumnPosition } = expandRow; const { showExpandColumn, expandColumnPosition } = expandRow;
const newAttrs = this.delegate({ ...attrs }); const newAttrs = this.delegate({ ...attrs });
@@ -95,7 +96,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
)]; )];
if (!hideSelectColumn) { if (!hideSelectColumn) {
childrens.unshift(( const selectCell = (
<SelectionCell <SelectionCell
{ ...selectRow } { ...selectRow }
key="selection-cell" key="selection-cell"
@@ -105,7 +106,12 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
disabled={ !selectable } disabled={ !selectable }
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 } tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
/> />
)); );
if (this.isRenderFunctionColumnInLeft(selectColumnPosition)) {
childrens.unshift(selectCell);
} else {
childrens.push(selectCell);
}
} }
if (showExpandColumn) { if (showExpandColumn) {
@@ -120,7 +126,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 } tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
/> />
); );
if (this.isRenderExpandColumnInLeft(expandColumnPosition)) { if (this.isRenderFunctionColumnInLeft(expandColumnPosition)) {
childrens.unshift(expandCell); childrens.unshift(expandCell);
} else { } else {
childrens.push(expandCell); childrens.push(expandCell);

View File

@@ -74,7 +74,7 @@ export default ExtendBase =>
delegate(attrs = {}) { delegate(attrs = {}) {
const newAttrs = { ...attrs }; const newAttrs = { ...attrs };
Object.keys(attrs).forEach((attr) => { Object.keys(attrs).forEach((attr) => {
if (events.includes(attr)) { if (_.contains(events, attr)) {
newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]); newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]);
} }
}); });

View File

@@ -48,4 +48,9 @@ export default ExtendBase =>
return this.shouldUpdateByCellEditing(nextProps) || return this.shouldUpdateByCellEditing(nextProps) ||
this.shouldUpdatedByNormalProps(nextProps); this.shouldUpdatedByNormalProps(nextProps);
} }
shouldRowContentUpdate(nextProps) {
return this.shouldUpdateChild(nextProps) ||
this.shouldUpdateByColumnsForSimpleCheck(nextProps);
}
}; };

View File

@@ -15,8 +15,7 @@ class SimpleRow extends shouldUpdater(eventDelegater(Component)) {
shouldComponentUpdate(nextProps) { shouldComponentUpdate(nextProps) {
this.shouldUpdateRowContent = false; this.shouldUpdateRowContent = false;
this.shouldUpdateRowContent = this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);
this.shouldUpdateChild(nextProps) || this.shouldUpdateByColumnsForSimpleCheck(nextProps);
if (this.shouldUpdateRowContent) return true; if (this.shouldUpdateRowContent) return true;
return this.shouldUpdatedBySelfProps(nextProps); return this.shouldUpdatedBySelfProps(nextProps);

View File

@@ -20,7 +20,7 @@ export const expandableKeys = (data, keyField, skips = []) => {
return data.map(row => _.get(row, keyField)); return data.map(row => _.get(row, keyField));
} }
return data return data
.filter(row => !skips.includes(_.get(row, keyField))) .filter(row => !_.contains(skips, _.get(row, keyField)))
.map(row => _.get(row, keyField)); .map(row => _.get(row, keyField));
}; };

View File

@@ -3,11 +3,13 @@ import * as selection from './selection';
import * as expand from './expand'; import * as expand from './expand';
import * as mutate from './mutate'; import * as mutate from './mutate';
import * as sort from './sort'; import * as sort from './sort';
import * as type from './type';
export default { export default {
...rows, ...rows,
...selection, ...selection,
...expand, ...expand,
...mutate, ...mutate,
...sort ...sort,
...type
}; };

View File

@@ -29,7 +29,7 @@ export const selectableKeys = (data, keyField, skips = []) => {
return data.map(row => _.get(row, keyField)); return data.map(row => _.get(row, keyField));
} }
return data return data
.filter(row => !skips.includes(_.get(row, keyField))) .filter(row => !_.contains(skips, _.get(row, keyField)))
.map(row => _.get(row, keyField)); .map(row => _.get(row, keyField));
}; };
@@ -37,7 +37,7 @@ export const unSelectableKeys = (selected, skips = []) => {
if (skips.length === 0) { if (skips.length === 0) {
return []; return [];
} }
return selected.filter(x => skips.includes(x)); return selected.filter(x => _.contains(skips, x));
}; };
export const getSelectedRows = (data, keyField, selected) => export const getSelectedRows = (data, keyField, selected) =>

View File

@@ -0,0 +1,18 @@
import Const from '../const';
export const typeConvert = (type, value) => {
if (!type || type === Const.TYPE_STRING) {
return String(value);
} else if (type === Const.TYPE_NUMBER) {
return Number(value);
} else if (type === Const.TYPE_BOOLEAN) {
if (typeof value === 'boolean') {
return value;
}
return value === 'true';
} else if (type === Const.TYPE_DATE) {
return new Date(value);
}
return value;
};