mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 21:50:07 +00:00
Compare commits
20 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d2a6a1b23 | ||
|
|
bb752fcec8 | ||
|
|
5a6b7e122d | ||
|
|
a7ae524c49 | ||
|
|
a23599f52f | ||
|
|
c50853b16d | ||
|
|
3f74542c98 | ||
|
|
47aa41b8fa | ||
|
|
67ed2e6c80 | ||
|
|
794a97956d | ||
|
|
78ca01bb1a | ||
|
|
b79dbc80f6 | ||
|
|
3f21a67620 | ||
|
|
9e3ae385ce | ||
|
|
c6ea19fe8a | ||
|
|
a5b42dca92 | ||
|
|
28f3c33db3 | ||
|
|
2530a70c00 | ||
|
|
569dd61463 | ||
|
|
68264b45ce |
41
README.md
41
README.md
@@ -1,43 +1,56 @@
|
|||||||
# react-bootstrap-table2
|
# react-bootstrap-table2
|
||||||
|
|
||||||
[](https://travis-ci.org/react-bootstrap-table/react-bootstrap-table2)
|
[](https://travis-ci.org/react-bootstrap-table/react-bootstrap-table2)
|
||||||
Rebuilt [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table)
|
Rebuilt of [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table)
|
||||||
|
|
||||||
> `react-bootstrap-table2`'s npm module name is [**`react-bootstrap-table-next`**](https://www.npmjs.com/package/react-bootstrap-table-next) due to some guys already used it
|
> Note that `react-bootstrap-table2`'s npm module name is [**`react-bootstrap-table-next`**](https://www.npmjs.com/package/react-bootstrap-table-next) due to the name being already taken.
|
||||||
|
|
||||||
`react-bootstrap-table2` separate some functionalities from core modules to other modules like following:
|
`react-bootstrap-table2` separates some functionalities from its core modules to other modules as listed in the following:
|
||||||
|
|
||||||
* [`react-bootstrap-table-next`](https://www.npmjs.com/package/react-bootstrap-table-next)
|
- [`react-bootstrap-table-next`](https://www.npmjs.com/package/react-bootstrap-table-next)
|
||||||
* [`react-bootstrap-table2-filter`](https://www.npmjs.com/package/react-bootstrap-table2-filter)
|
- [`react-bootstrap-table2-filter`](https://www.npmjs.com/package/react-bootstrap-table2-filter)
|
||||||
* [`react-bootstrap-table2-editor`](https://www.npmjs.com/package/react-bootstrap-table2-editor)
|
- [`react-bootstrap-table2-editor`](https://www.npmjs.com/package/react-bootstrap-table2-editor)
|
||||||
* [`react-bootstrap-table2-paginator`](https://www.npmjs.com/package/react-bootstrap-table2-paginator)
|
- [`react-bootstrap-table2-paginator`](https://www.npmjs.com/package/react-bootstrap-table2-paginator)
|
||||||
* [`react-bootstrap-table2-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay)
|
- [`react-bootstrap-table2-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay)
|
||||||
* [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit)
|
- [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit)
|
||||||
|
|
||||||
This can help your application with less bundled size and also help us have clean design to avoid handling to much logic in kernel module(SRP).
|
Not only does this reduce the bundle size of your apps but also helps us have a cleaner design to avoid handling too much logic in the kernel module(SRP).
|
||||||
|
|
||||||
## Migration
|
## Migration
|
||||||
If you are the user from legacy [`react-bootstrap-table`](https://github.com/AllenFang/react-bootstrap-table/), please have a look on [this](./docs/migration.md).
|
|
||||||
|
If you are coming from the legacy [`react-bootstrap-table`](https://github.com/AllenFang/react-bootstrap-table/), please check out the [migration guide](./docs/migration.md).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
See [getting started](https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/getting-started.html).
|
See [getting started](https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/getting-started.html).
|
||||||
|
|
||||||
## Online Demo
|
## Online Demo
|
||||||
|
|
||||||
See `react-bootstrap-table2` [storybook](https://react-bootstrap-table.github.io/react-bootstrap-table2/storybook/index.html).
|
See `react-bootstrap-table2` [storybook](https://react-bootstrap-table.github.io/react-bootstrap-table2/storybook/index.html).
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
See [release plans](https://react-bootstrap-table.github.io/react-bootstrap-table2/blog/2018/01/24/release-plan.html).
|
See [release plans](https://react-bootstrap-table.github.io/react-bootstrap-table2/blog/2018/01/24/release-plan.html).
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
Please check [development guide](./docs/development.md).
|
|
||||||
|
|
||||||
## How should I run storybook example in my local?
|
Please check the [development guide](./docs/development.md).
|
||||||
|
|
||||||
|
## Running storybook example on your local machine
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
# Clone the repo
|
||||||
$ git clone https://github.com/react-bootstrap-table/react-bootstrap-table2.git
|
$ git clone https://github.com/react-bootstrap-table/react-bootstrap-table2.git
|
||||||
|
|
||||||
|
# change dir to the cloned repo
|
||||||
$ cd react-bootstrap-table2
|
$ cd react-bootstrap-table2
|
||||||
|
|
||||||
|
# Install all dependencies with yarn
|
||||||
$ yarn install
|
$ yarn install
|
||||||
|
|
||||||
|
# Start the stroybook server, then go to localhost:6006
|
||||||
$ yarn storybook
|
$ yarn storybook
|
||||||
$ Go to localhost:6006
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Storybook examples: [`packages/react-bootstrap-table2-example/examples`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples)**
|
**Storybook examples: [`packages/react-bootstrap-table2-example/examples`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples)**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-editor",
|
"name": "react-bootstrap-table2-editor",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
const EditorIndicator = ({ invalidMessage }) =>
|
const EditorIndicator = ({ invalidMessage }) =>
|
||||||
(
|
(
|
||||||
<div className="alert alert-danger fade in">
|
<div className="alert alert-danger in" role="alert">
|
||||||
<strong>{ invalidMessage }</strong>
|
<strong>{ invalidMessage }</strong>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ const columns = [{
|
|||||||
}, {
|
}, {
|
||||||
dataField: 'quality',
|
dataField: 'quality',
|
||||||
text: 'Product Quality',
|
text: 'Product Quality',
|
||||||
editorRenderer: (editorProps, value, row, rowIndex, columnIndex) => (
|
editorRenderer: (editorProps, value, row, column, rowIndex, columnIndex) => (
|
||||||
<QualityRanger { ...editorProps } value={ value } />
|
<QualityRanger { ...editorProps } value={ value } />
|
||||||
)
|
)
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import { productsQualityGenerator } from 'utils/common';
|
|||||||
const products = productsQualityGenerator(6);
|
const products = productsQualityGenerator(6);
|
||||||
|
|
||||||
const selectOptions = [
|
const selectOptions = [
|
||||||
{ label: 0, value: 'good' },
|
{ value: 0, label: 'good' },
|
||||||
{ label: 1, value: 'Bad' },
|
{ value: 1, label: 'Bad' },
|
||||||
{ label: 2, value: 'unknown' }
|
{ value: 2, label: 'unknown' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
@@ -22,7 +22,7 @@ const columns = [{
|
|||||||
}, {
|
}, {
|
||||||
dataField: 'quality',
|
dataField: 'quality',
|
||||||
text: 'Product Quailty',
|
text: 'Product Quailty',
|
||||||
formatter: cell => selectOptions.find(opt => opt.label === cell).value,
|
formatter: cell => selectOptions.find(opt => opt.value === cell).label,
|
||||||
filter: selectFilter({
|
filter: selectFilter({
|
||||||
options: selectOptions
|
options: selectOptions
|
||||||
})
|
})
|
||||||
@@ -33,9 +33,9 @@ import BootstrapTable from 'react-bootstrap-table-next';
|
|||||||
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
const selectOptions = [
|
const selectOptions = [
|
||||||
{ label: 0, value: 'good' },
|
{ value: 0, label: 'good' },
|
||||||
{ label: 1, value: 'Bad' },
|
{ value: 1, label: 'Bad' },
|
||||||
{ label: 2, value: 'unknown' }
|
{ value: 2, label: 'unknown' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
@@ -47,7 +47,7 @@ const columns = [{
|
|||||||
}, {
|
}, {
|
||||||
dataField: 'quality',
|
dataField: 'quality',
|
||||||
text: 'Product Quailty',
|
text: 'Product Quailty',
|
||||||
formatter: cell => selectOptions.find(opt => opt.label === cell).value,
|
formatter: cell => selectOptions.find(opt => opt.value === cell).label,
|
||||||
filter: selectFilter({
|
filter: selectFilter({
|
||||||
options: selectOptions
|
options: selectOptions
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import React from 'react';
|
|||||||
|
|
||||||
import BootstrapTable from 'react-bootstrap-table-next';
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
import Code from 'components/common/code-block';
|
import Code from 'components/common/code-block';
|
||||||
import { productsGenerator } from 'utils/common';
|
import { productsGenerator, withOnSale } from 'utils/common';
|
||||||
|
|
||||||
const products = productsGenerator();
|
const products = withOnSale(productsGenerator());
|
||||||
|
|
||||||
function priceFormatter(cell, row) {
|
function priceFormatter(cell, row) {
|
||||||
if (row.onSale) {
|
if (row.onSale) {
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ const expandRow = {
|
|||||||
<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>
|
||||||
),
|
),
|
||||||
showExpandColumn: true
|
showExpandColumn: true,
|
||||||
|
expandByColumnOnly: true
|
||||||
};
|
};
|
||||||
|
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.9",
|
"version": "1.0.11",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* eslint no-mixed-operators: 0 */
|
/* eslint no-mixed-operators: 0 */
|
||||||
|
/* eslint no-param-reassign: 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* products generator for stories
|
* products generator for stories
|
||||||
@@ -22,6 +23,12 @@ export const productsGenerator = (quantity = 5, callback) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const withOnSale = rows => rows.map((row) => {
|
||||||
|
if (row.id > 2) row.onSale = false;
|
||||||
|
else row.onSale = true;
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
|
||||||
export const productsQualityGenerator = (quantity = 5) =>
|
export const productsQualityGenerator = (quantity = 5) =>
|
||||||
Array.from({ length: quantity }, (value, index) => ({
|
Array.from({ length: quantity }, (value, index) => ({
|
||||||
id: index,
|
id: index,
|
||||||
|
|||||||
@@ -119,15 +119,15 @@ const qualityFilter = selectFilter({
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const selectOptions = [
|
const selectOptions = [
|
||||||
{ label: 0, value: 'good' },
|
{ value: 0, label: 'good' },
|
||||||
{ label: 1, value: 'Bad' },
|
{ value: 1, label: 'Bad' },
|
||||||
{ label: 2, value: 'unknown' }
|
{ value: 2, label: 'unknown' }
|
||||||
];
|
];
|
||||||
const columns = [
|
const columns = [
|
||||||
..., {
|
..., {
|
||||||
dataField: 'quality',
|
dataField: 'quality',
|
||||||
text: 'Product Quailty',
|
text: 'Product Quailty',
|
||||||
formatter: cell => selectOptions.find(opt => opt.label === cell).value,
|
formatter: cell => selectOptions.find(opt => opt.value === cell).label,
|
||||||
filter: selectFilter({
|
filter: selectFilter({
|
||||||
options: selectOptions
|
options: selectOptions
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-filter",
|
"name": "react-bootstrap-table2-filter",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import { FILTER_TYPE } from '../const';
|
|||||||
function optionsEquals(currOpts, prevOpts) {
|
function optionsEquals(currOpts, prevOpts) {
|
||||||
if (Array.isArray(currOpts)) {
|
if (Array.isArray(currOpts)) {
|
||||||
for (let i = 0; i < currOpts.length; i += 1) {
|
for (let i = 0; i < currOpts.length; i += 1) {
|
||||||
if (currOpts[i].label !== prevOpts[i].label) {
|
if (
|
||||||
|
currOpts[i].value !== prevOpts[i].value ||
|
||||||
|
currOpts[i].label !== prevOpts[i].label
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +89,7 @@ class SelectFilter extends Component {
|
|||||||
}
|
}
|
||||||
if (Array.isArray(options)) {
|
if (Array.isArray(options)) {
|
||||||
options.forEach(({ value, label }) =>
|
options.forEach(({ value, label }) =>
|
||||||
optionTags.push(<option key={ label } value={ label }>{ value }</option>));
|
optionTags.push(<option key={ value } value={ value }>{ label }</option>));
|
||||||
} else {
|
} else {
|
||||||
Object.keys(options).forEach(key =>
|
Object.keys(options).forEach(key =>
|
||||||
optionTags.push(<option key={ key } value={ key }>{ options[key] }</option>)
|
optionTags.push(<option key={ key } value={ key }>{ options[key] }</option>)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-paginator",
|
"name": "react-bootstrap-table2-paginator",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
const PaginationTotal = props => (
|
const PaginationTotal = props => (
|
||||||
<span className="react-bootstrap-table-pagination-total">
|
<span className="react-bootstrap-table-pagination-total">
|
||||||
Showing rows { props.from } to { props.to + 1 } of { props.dataSize }
|
Showing rows { props.from } to { props.to } of { props.dataSize }
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "1.4.0",
|
"version": "1.4.2",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
tabIndexCell,
|
tabIndexCell,
|
||||||
id,
|
id,
|
||||||
classes,
|
classes,
|
||||||
|
bootstrap4,
|
||||||
striped,
|
striped,
|
||||||
hover,
|
hover,
|
||||||
bordered,
|
bordered,
|
||||||
@@ -66,7 +67,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
'table-striped': striped,
|
'table-striped': striped,
|
||||||
'table-hover': hover,
|
'table-hover': hover,
|
||||||
'table-bordered': bordered,
|
'table-bordered': bordered,
|
||||||
'table-condensed': condensed
|
[(bootstrap4 ? 'table-sm' : 'table-condensed')]: condensed
|
||||||
}, classes);
|
}, classes);
|
||||||
|
|
||||||
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
||||||
|
|||||||
@@ -43,12 +43,13 @@ class SelectionProvider extends React.Component {
|
|||||||
|
|
||||||
let currSelected = [...this.state.selected];
|
let currSelected = [...this.state.selected];
|
||||||
|
|
||||||
this.setState(() => {
|
|
||||||
let result = true;
|
let result = true;
|
||||||
if (onSelect) {
|
if (onSelect) {
|
||||||
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
|
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
|
||||||
result = onSelect(row, checked, rowIndex, e);
|
result = onSelect(row, checked, rowIndex, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setState(() => {
|
||||||
if (result === true || result === undefined) {
|
if (result === true || result === undefined) {
|
||||||
if (mode === ROW_SELECT_SINGLE) { // when select mode is radio
|
if (mode === ROW_SELECT_SINGLE) { // when select mode is radio
|
||||||
currSelected = [rowKey];
|
currSelected = [rowKey];
|
||||||
@@ -81,7 +82,6 @@ class SelectionProvider extends React.Component {
|
|||||||
currSelected = selected.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
currSelected = selected.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState(() => {
|
|
||||||
let result;
|
let result;
|
||||||
if (onSelectAll) {
|
if (onSelectAll) {
|
||||||
result = onSelectAll(
|
result = onSelectAll(
|
||||||
@@ -97,8 +97,7 @@ class SelectionProvider extends React.Component {
|
|||||||
currSelected = result;
|
currSelected = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { selected: currSelected };
|
this.setState(() => ({ selected: currSelected }));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ const Header = (props) => {
|
|||||||
sortOrder,
|
sortOrder,
|
||||||
selectRow,
|
selectRow,
|
||||||
onExternalFilter,
|
onExternalFilter,
|
||||||
expandRow,
|
expandRow
|
||||||
bootstrap4
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
let SelectionHeaderCellComp = () => null;
|
let SelectionHeaderCellComp = () => null;
|
||||||
@@ -50,7 +49,6 @@ const Header = (props) => {
|
|||||||
return (
|
return (
|
||||||
<HeaderCell
|
<HeaderCell
|
||||||
index={ i }
|
index={ i }
|
||||||
bootstrap4={ bootstrap4 }
|
|
||||||
key={ column.dataField }
|
key={ column.dataField }
|
||||||
column={ column }
|
column={ column }
|
||||||
onSort={ onSort }
|
onSort={ onSort }
|
||||||
@@ -78,8 +76,7 @@ Header.propTypes = {
|
|||||||
selectRow: PropTypes.object,
|
selectRow: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func,
|
onExternalFilter: PropTypes.func,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
expandRow: PropTypes.object,
|
expandRow: PropTypes.object
|
||||||
bootstrap4: PropTypes.bool
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Header;
|
export default Header;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export default class ExpandCell extends Component {
|
|||||||
|
|
||||||
handleClick(e) {
|
handleClick(e) {
|
||||||
const { rowKey, expanded, onRowExpand, rowIndex } = this.props;
|
const { rowKey, expanded, onRowExpand, rowIndex } = this.props;
|
||||||
|
e.stopPropagation();
|
||||||
onRowExpand(rowKey, !expanded, rowIndex, e);
|
onRowExpand(rowKey, !expanded, rowIndex, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user