mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 13:40:07 +00:00
Compare commits
28 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb42514e56 | ||
|
|
79e3247921 | ||
|
|
c25192145f | ||
|
|
056957b0b5 | ||
|
|
c12d3faba3 | ||
|
|
963b8d669b | ||
|
|
47f6340a99 | ||
|
|
23cb0bb317 | ||
|
|
70827eecd6 | ||
|
|
43b5eeb74f | ||
|
|
eb204f6526 | ||
|
|
110744f4cb | ||
|
|
47848e7f34 | ||
|
|
1a44ce0ea6 | ||
|
|
08ec8a9f65 | ||
|
|
27387c2a69 | ||
|
|
05b50ac71a | ||
|
|
9b6d9904e7 | ||
|
|
4de565b759 | ||
|
|
c53d2612d4 | ||
|
|
0c2863d63c | ||
|
|
a534d525c9 | ||
|
|
856e63d524 | ||
|
|
c59b963436 | ||
|
|
b50dc95e06 | ||
|
|
2619a1e424 | ||
|
|
423769c134 | ||
|
|
6530ff1570 |
24
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
24
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: AllenFang
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is. In addition, please search issues before you open a report to make sure there's no any duplicated report
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**codesandbox**
|
||||
Please give a simple and minimal example on https://codesandbox.io so that we can reproduce it easily and handle it effectively
|
||||
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: AllenFang
|
||||
|
||||
---
|
||||
|
||||
**Is this feature requested before?**
|
||||
Please search issues to make sure to create feature which is never report yet.
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
17
.github/ISSUE_TEMPLATE/i-have-a-question.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/i-have-a-question.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: I have a question
|
||||
about: I have a question
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: AllenFang
|
||||
|
||||
---
|
||||
|
||||
**Question**
|
||||
A clear and concise description of you question. In addition, please search issues before you open a question to make sure there's no any duplicated questions.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**codesandbox**
|
||||
Please give a simple and minimal example on https://codesandbox.io so that we can reproduce it easily.
|
||||
@@ -1,7 +1,7 @@
|
||||
# react-bootstrap-table2
|
||||
|
||||
[](https://travis-ci.org/react-bootstrap-table/react-bootstrap-table2)
|
||||
Rebuilt of [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table)
|
||||
Rebuild of [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table)
|
||||
|
||||
> 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.
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ Available properties in a column object:
|
||||
* [editorRenderer](#editorRenderer)
|
||||
* [filter](#filter)
|
||||
* [filterValue](#filterValue)
|
||||
* [searchable](#searchable)
|
||||
* [csvType](#csvType)
|
||||
* [csvFormatter](#csvFormatter)
|
||||
* [csvText](#csvText)
|
||||
@@ -917,6 +918,9 @@ A final `String` value you want to be filtered.
|
||||
}
|
||||
```
|
||||
|
||||
## <a name='searchable'>column.searchable - [Boolean]</a>
|
||||
Default the column is searchable. Give `false` to disable search functionality on specified column.
|
||||
|
||||
## <a name='csvType'>column.csvType - [Object]</a>
|
||||
Default is `String`. Currently, the available value is `String` and `Number`. If `Number` assigned, the cell value will not wrapped with double quote.
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* [expandColumnPosition](#expandColumnPosition)
|
||||
* [expandColumnRenderer](#expandColumnRenderer)
|
||||
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
|
||||
* [className](#className)
|
||||
* [parentClassName](#parentClassName)
|
||||
|
||||
### <a name="renderer">expandRow.renderer - [Function]</a>
|
||||
@@ -168,6 +169,27 @@ const expandRow = {
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='className'>expandRow.className - [String | Function]</a>
|
||||
Apply the custom class name on the expanding row. For example:
|
||||
|
||||
```js
|
||||
const expandRow = {
|
||||
renderer: (row) => ...,
|
||||
className: 'foo'
|
||||
};
|
||||
```
|
||||
following usage is more flexible way for customing the class name:
|
||||
|
||||
```js
|
||||
const expandRow = {
|
||||
renderer: (row) => ...,
|
||||
className: (isExpanded, row, rowIndex) => {
|
||||
if (rowIndex > 2) return 'foo';
|
||||
return 'bar';
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='parentClassName'>expandRow.parentClassName - [String | Function]</a>
|
||||
Apply the custom class name on parent row of expanded row. For example:
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ const columns = [
|
||||
text: 'Job Type',
|
||||
editor: {
|
||||
type: Type.SELECT,
|
||||
getOptions: () => [.....]
|
||||
getOptions: (setOptions, { row, column }) => [.....]
|
||||
}
|
||||
}];
|
||||
|
||||
@@ -152,7 +152,7 @@ const columns = [
|
||||
text: 'Job Type',
|
||||
editor: {
|
||||
type: Type.SELECT,
|
||||
getOptions: (setOptions) => {
|
||||
getOptions: (setOptions, { row, column }) => {
|
||||
setTimeout(() => setOptions([...]), 1500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-editor",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"description": "it's the editor addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -8,7 +8,13 @@ class DropDownEditor extends Component {
|
||||
super(props);
|
||||
let options = props.options;
|
||||
if (props.getOptions) {
|
||||
options = props.getOptions(this.setOptions.bind(this)) || [];
|
||||
options = props.getOptions(
|
||||
this.setOptions.bind(this),
|
||||
{
|
||||
row: props.row,
|
||||
column: props.column
|
||||
}
|
||||
) || [];
|
||||
}
|
||||
this.state = { options };
|
||||
}
|
||||
@@ -54,6 +60,8 @@ class DropDownEditor extends Component {
|
||||
}
|
||||
|
||||
DropDownEditor.propTypes = {
|
||||
row: PropTypes.object.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
defaultValue: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.number
|
||||
|
||||
@@ -201,7 +201,7 @@ export default (_, onStartEdit) =>
|
||||
if (_.isFunction(column.editorRenderer)) {
|
||||
editor = column.editorRenderer(editorProps, value, row, column, rowIndex, columnIndex);
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
|
||||
editor = <DropdownEditor { ...editorProps } />;
|
||||
editor = <DropdownEditor { ...editorProps } row={ row } column={ column } />;
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
|
||||
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint no-console: 0 */
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
import React from 'react';
|
||||
|
||||
@@ -25,22 +26,26 @@ const columns = [{
|
||||
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'
|
||||
}]
|
||||
getOptions: (setOptions, { row, column }) => {
|
||||
console.log(`current editing row id: ${row.id}`);
|
||||
console.log(`current editing column: ${column.dataField}`);
|
||||
return [{
|
||||
value: 'A',
|
||||
label: 'A'
|
||||
}, {
|
||||
value: 'B',
|
||||
label: 'B'
|
||||
}, {
|
||||
value: 'C',
|
||||
label: 'C'
|
||||
}, {
|
||||
value: 'D',
|
||||
label: 'D'
|
||||
}, {
|
||||
value: 'E',
|
||||
label: 'E'
|
||||
}];
|
||||
}
|
||||
}
|
||||
}, {
|
||||
dataField: 'type2',
|
||||
@@ -88,22 +93,26 @@ const columns = [{
|
||||
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'
|
||||
}]
|
||||
getOptions: (setOptions, { row, column }) => {
|
||||
console.log(\`current editing row id: $\{row.id}\`);
|
||||
console.log(\`current editing column: $\{column.dataField}\`);
|
||||
return [{
|
||||
value: 'A',
|
||||
label: 'A'
|
||||
}, {
|
||||
value: 'B',
|
||||
label: 'B'
|
||||
}, {
|
||||
value: 'C',
|
||||
label: 'C'
|
||||
}, {
|
||||
value: 'D',
|
||||
label: 'D'
|
||||
}, {
|
||||
value: 'E',
|
||||
label: 'E'
|
||||
}];
|
||||
}
|
||||
}
|
||||
}, {
|
||||
dataField: 'type2',
|
||||
|
||||
@@ -12,11 +12,11 @@ import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
class Table extends React.Component {
|
||||
filterByPrice = (filterVal) => {
|
||||
filterByPrice = (filterVal, data) => {
|
||||
if (filterVal) {
|
||||
return products.filter(product => product.price == filterVal);
|
||||
return data.filter(product => product.price == filterVal);
|
||||
}
|
||||
return products;
|
||||
return data;
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -50,11 +50,11 @@ class Table extends React.Component {
|
||||
`;
|
||||
|
||||
export default class Table extends React.Component {
|
||||
filterByPrice = (filterVal) => {
|
||||
filterByPrice = (filterVal, data) => {
|
||||
if (filterVal) {
|
||||
return products.filter(product => product.price == filterVal);
|
||||
return data.filter(product => product.price == filterVal);
|
||||
}
|
||||
return products;
|
||||
return data;
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -75,7 +75,7 @@ export default class Table extends React.Component {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Implement Custom Filter</h2>
|
||||
<h2>Implement a eq price filter</h2>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
|
||||
150
packages/react-bootstrap-table2-example/examples/column-filter/select-filter-option-type.js
vendored
Normal file
150
packages/react-bootstrap-table2-example/examples/column-filter/select-filter-option-type.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
import React from 'react';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsQualityGenerator } from 'utils/common';
|
||||
|
||||
const products = productsQualityGenerator(6);
|
||||
|
||||
const selectOptions = {
|
||||
0: 'good',
|
||||
1: 'Bad',
|
||||
2: 'unknown'
|
||||
};
|
||||
|
||||
const selectOptionsArr = [{
|
||||
value: 0,
|
||||
label: 'good'
|
||||
}, {
|
||||
value: 1,
|
||||
label: 'Bad'
|
||||
}, {
|
||||
value: 2,
|
||||
label: 'unknown'
|
||||
}];
|
||||
|
||||
const columns1 = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptions[cell],
|
||||
filter: selectFilter({
|
||||
options: selectOptions
|
||||
})
|
||||
}];
|
||||
|
||||
const columns2 = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
|
||||
filter: selectFilter({
|
||||
options: selectOptionsArr
|
||||
})
|
||||
}];
|
||||
|
||||
const columns3 = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
|
||||
filter: selectFilter({
|
||||
options: () => selectOptionsArr
|
||||
})
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
// Object map options
|
||||
const selectOptions = {
|
||||
0: 'good',
|
||||
1: 'Bad',
|
||||
2: 'unknown'
|
||||
};
|
||||
|
||||
// Array options
|
||||
const selectOptionsArr = [{
|
||||
value: 0,
|
||||
label: 'good'
|
||||
}, {
|
||||
value: 1,
|
||||
label: 'Bad'
|
||||
}, {
|
||||
value: 2,
|
||||
label: 'unknown'
|
||||
}];
|
||||
|
||||
const columns1 = [..., {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptions[cell],
|
||||
filter: selectFilter({
|
||||
options: selectOptions
|
||||
})
|
||||
}];
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns1 } filter={ filterFactory() } />
|
||||
|
||||
const columns2 = [..., {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
|
||||
filter: selectFilter({
|
||||
options: selectOptionsArr
|
||||
})
|
||||
}];
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns2 } filter={ filterFactory() } />
|
||||
|
||||
const columns3 = [..., {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
|
||||
filter: selectFilter({
|
||||
options: () => selectOptionsArr
|
||||
})
|
||||
}];
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns3 } filter={ filterFactory() } />
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h2>Options as an object</h2>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns1 }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
<h2>Options as an array</h2>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns2 }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
<h2>Options as a function which return an array</h2>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns3 }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
94
packages/react-bootstrap-table2-example/examples/column-toggle/column-toggle-with-filter.js
vendored
Normal file
94
packages/react-bootstrap-table2-example/examples/column-toggle/column-toggle-with-filter.js
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/* eslint react/prop-types: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const { ToggleList } = ColumnToggle;
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
sort: true,
|
||||
filter: textFilter()
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
sort: true,
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
|
||||
|
||||
const { ToggleList } = ColumnToggle;
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
sort: true,
|
||||
filter: textFilter()
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
sort: true,
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
columnToggle
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<ToggleList { ...props.columnToggleProps } />
|
||||
<hr />
|
||||
<BootstrapTable
|
||||
{ ...props.baseProps }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Table will keep the filter/sort state when column toggle</h3>
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
columnToggle
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<ToggleList { ...props.columnToggleProps } />
|
||||
<hr />
|
||||
<BootstrapTable
|
||||
{ ...props.baseProps }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
106
packages/react-bootstrap-table2-example/examples/row-expand/expanding-row-classname.js
vendored
Normal file
106
packages/react-bootstrap-table2-example/examples/row-expand/expanding-row-classname.js
vendored
Normal 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 = {
|
||||
className: 'expanding-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 = {
|
||||
className: (isExpanded, row, rowIndex) => {
|
||||
if (rowIndex > 2) return 'expanding-foo';
|
||||
return 'expanding-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 = {
|
||||
className: 'expanding-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 = {
|
||||
className: (isExpanded, row, rowIndex) => {
|
||||
if (rowIndex > 2) return 'expanding-foo';
|
||||
return 'expanding-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>
|
||||
);
|
||||
87
packages/react-bootstrap-table2-example/examples/search/searchable-column.js
vendored
Normal file
87
packages/react-bootstrap-table2-example/examples/search/searchable-column.js
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/* eslint react/prop-types: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const { SearchBar } = Search;
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
searchable: false
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
searchable: false
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
|
||||
|
||||
const { SearchBar } = Search;
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
searchable: false
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
searchable: false
|
||||
}];
|
||||
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
search
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<h3>Input something at below input field:</h3>
|
||||
<SearchBar { ...props.searchProps } />
|
||||
<hr />
|
||||
<BootstrapTable
|
||||
{ ...props.baseProps }
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
search
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<h3>Column name and price is unsearchable</h3>
|
||||
<SearchBar { ...props.searchProps } />
|
||||
<hr />
|
||||
<BootstrapTable
|
||||
{ ...props.baseProps }
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-example",
|
||||
"version": "1.0.28",
|
||||
"version": "1.0.30",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
||||
@@ -68,6 +68,7 @@ import TextFilterCaseSensitive from 'examples/column-filter/text-filter-caseSens
|
||||
import CustomTextFilter from 'examples/column-filter/custom-text-filter';
|
||||
import CustomFilterValue from 'examples/column-filter/custom-filter-value';
|
||||
import SelectFilter from 'examples/column-filter/select-filter';
|
||||
import ConfigureSelectFilterOptions from 'examples/column-filter/select-filter-option-type';
|
||||
import SelectFilterWithDefaultValue from 'examples/column-filter/select-filter-default-value';
|
||||
import SelectFilterComparator from 'examples/column-filter/select-filter-like-comparator';
|
||||
import SelectFilterWithPreservedOptionsOrder from 'examples/column-filter/select-filter-preserve-option-order';
|
||||
@@ -166,6 +167,7 @@ import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
|
||||
import ExpandColumnPosition from 'examples/row-expand/expand-column-position';
|
||||
import ExpandHooks from 'examples/row-expand/expand-hooks';
|
||||
import ParentRowClassName from 'examples/row-expand/parent-row-classname';
|
||||
import ExpandingRowClassName from 'examples/row-expand/expanding-row-classname';
|
||||
|
||||
// pagination
|
||||
import PaginationTable from 'examples/pagination';
|
||||
@@ -192,6 +194,7 @@ import DefaultCustomSearch from 'examples/search/default-custom-search';
|
||||
import FullyCustomSearch from 'examples/search/fully-custom-search';
|
||||
import SearchFormattedData from 'examples/search/search-formatted';
|
||||
import CustomSearchValue from 'examples/search/custom-search-value';
|
||||
import SearchableColumn from 'examples/search/searchable-column';
|
||||
|
||||
// CSV
|
||||
import ExportCSV from 'examples/csv';
|
||||
@@ -210,6 +213,7 @@ import BasicColumnToggle from 'examples/column-toggle';
|
||||
import DefaultVisibility from 'examples/column-toggle/default-visibility';
|
||||
import StylingColumnToggle from 'examples/column-toggle/styling-toggle-list';
|
||||
import CustomToggleList from 'examples/column-toggle/custom-toggle-list';
|
||||
import ColumnToggleWithFilter from 'examples/column-toggle/column-toggle-with-filter';
|
||||
|
||||
// loading overlay
|
||||
import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay';
|
||||
@@ -299,6 +303,7 @@ storiesOf('Column Filter', module)
|
||||
.add('Text Filter with Case Sensitive', () => <TextFilterCaseSensitive />)
|
||||
// add another filter type example right here.
|
||||
.add('Select Filter', () => <SelectFilter />)
|
||||
.add('Configure Select Filter Options', () => <ConfigureSelectFilterOptions />)
|
||||
.add('Select Filter with Default Value', () => <SelectFilterWithDefaultValue />)
|
||||
.add('Select Filter with Comparator', () => <SelectFilterComparator />)
|
||||
.add('MultiSelect Filter', () => <MultiSelectFilter />)
|
||||
@@ -416,7 +421,8 @@ storiesOf('Row Expand', module)
|
||||
.add('Custom Expand Indicator', () => <CustomExpandColumn />)
|
||||
.add('Expand Column Position', () => <ExpandColumnPosition />)
|
||||
.add('Expand Hooks', () => <ExpandHooks />)
|
||||
.add('Custom Parent Row ClassName', () => <ParentRowClassName />);
|
||||
.add('Custom Parent Row ClassName', () => <ParentRowClassName />)
|
||||
.add('Custom Expanding Row ClassName', () => <ExpandingRowClassName />);
|
||||
|
||||
storiesOf('Pagination', module)
|
||||
.addDecorator(bootstrapStyle())
|
||||
@@ -442,8 +448,9 @@ storiesOf('Table Search', module)
|
||||
.add('Clear Search Button', () => <ClearSearchButton />)
|
||||
.add('Default Search Table', () => <DefaultSearch />)
|
||||
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
||||
.add('Searchable Column', () => <SearchableColumn />)
|
||||
.add('Fully Custom Search', () => <FullyCustomSearch />)
|
||||
.add('Search Fromatted Value', () => <SearchFormattedData />)
|
||||
.add('Search Formatted Value', () => <SearchFormattedData />)
|
||||
.add('Custom Search Value', () => <CustomSearchValue />);
|
||||
|
||||
storiesOf('Column Toggle', module)
|
||||
@@ -451,7 +458,8 @@ storiesOf('Column Toggle', module)
|
||||
.add('Basic Column Toggle', () => <BasicColumnToggle />)
|
||||
.add('Default Visibility', () => <DefaultVisibility />)
|
||||
.add('Styling Column Toggle', () => <StylingColumnToggle />)
|
||||
.add('Custom Column Toggle', () => <CustomToggleList />);
|
||||
.add('Custom Column Toggle', () => <CustomToggleList />)
|
||||
.add('Column Toggle with Filter', () => <ColumnToggleWithFilter />);
|
||||
|
||||
storiesOf('Export CSV', module)
|
||||
.addDecorator(bootstrapStyle())
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.parent-expand-foo {
|
||||
.expanding-foo, .parent-expand-foo {
|
||||
background-color: coral;
|
||||
}
|
||||
|
||||
.parent-expand-bar {
|
||||
.expanding-bar, .parent-expand-bar {
|
||||
background-color: aqua;
|
||||
}
|
||||
@@ -115,7 +115,9 @@ const qualityFilter = selectFilter({
|
||||
// omit...
|
||||
```
|
||||
|
||||
> Note, the selectOptions can be an array also:
|
||||
> Note, the selectOptions can be an array or a function which return an array:
|
||||
|
||||
### Array as options
|
||||
|
||||
```js
|
||||
const selectOptions = [
|
||||
@@ -133,6 +135,24 @@ const columns = [
|
||||
})
|
||||
}];
|
||||
```
|
||||
### Function as options
|
||||
|
||||
```js
|
||||
const selectOptions = [
|
||||
{ value: 0, label: 'good' },
|
||||
{ value: 1, label: 'Bad' },
|
||||
{ value: 2, label: 'unknown' }
|
||||
];
|
||||
const columns = [
|
||||
..., {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quailty',
|
||||
formatter: cell => selectOptions.find(opt => opt.value === cell).label,
|
||||
filter: selectFilter({
|
||||
options: () => selectOptions
|
||||
})
|
||||
}];
|
||||
```
|
||||
|
||||
The benifit is `react-bootstrap-table2` will render the select options by the order of array.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-filter",
|
||||
"version": "1.1.10",
|
||||
"version": "1.1.12",
|
||||
"description": "it's a column filter addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -83,14 +83,27 @@ class DateFilter extends Component {
|
||||
return optionTags;
|
||||
}
|
||||
|
||||
getDefaultDate() {
|
||||
let defaultDate = '';
|
||||
const { defaultValue } = this.props;
|
||||
if (defaultValue && defaultValue.date) {
|
||||
// Set the appropriate format for the input type=date, i.e. "YYYY-MM-DD"
|
||||
defaultDate = dateParser(new Date(defaultValue.date));
|
||||
getDefaultComparator() {
|
||||
const { defaultValue, filterState } = this.props;
|
||||
if (filterState && filterState.filterVal) {
|
||||
return filterState.filterVal.comparator;
|
||||
}
|
||||
return defaultDate;
|
||||
if (defaultValue && defaultValue.comparator) {
|
||||
return defaultValue.comparator;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getDefaultDate() {
|
||||
// Set the appropriate format for the input type=date, i.e. "YYYY-MM-DD"
|
||||
const { defaultValue, filterState } = this.props;
|
||||
if (filterState && filterState.filterVal && filterState.filterVal.date) {
|
||||
return dateParser(filterState.filterVal.date);
|
||||
}
|
||||
if (defaultValue && defaultValue.date) {
|
||||
return dateParser(new Date(defaultValue.date));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
applyFilter(value, comparator, isInitial) {
|
||||
@@ -122,8 +135,7 @@ class DateFilter extends Component {
|
||||
dateStyle,
|
||||
className,
|
||||
comparatorClassName,
|
||||
dateClassName,
|
||||
defaultValue
|
||||
dateClassName
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
@@ -143,7 +155,7 @@ class DateFilter extends Component {
|
||||
style={ comparatorStyle }
|
||||
className={ `date-filter-comparator form-control ${comparatorClassName}` }
|
||||
onChange={ this.onChangeComparator }
|
||||
defaultValue={ defaultValue ? defaultValue.comparator : '' }
|
||||
defaultValue={ this.getDefaultComparator() }
|
||||
>
|
||||
{ this.getComparatorOptions() }
|
||||
</select>
|
||||
@@ -169,6 +181,7 @@ class DateFilter extends Component {
|
||||
DateFilter.propTypes = {
|
||||
onFilter: PropTypes.func.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
filterState: PropTypes.object,
|
||||
delay: PropTypes.number,
|
||||
defaultValue: PropTypes.shape({
|
||||
date: PropTypes.oneOfType([PropTypes.object]),
|
||||
@@ -210,6 +223,7 @@ DateFilter.defaultProps = {
|
||||
date: undefined,
|
||||
comparator: ''
|
||||
},
|
||||
filterState: {},
|
||||
withoutEmptyComparatorOption: false,
|
||||
comparators: legalComparators,
|
||||
placeholder: undefined,
|
||||
|
||||
@@ -65,10 +65,18 @@ class MultiSelectFilter extends Component {
|
||||
needFilter = true;
|
||||
}
|
||||
if (needFilter) {
|
||||
this.applyFilter(this.selectInput.value);
|
||||
this.applyFilter(getSelections(this.selectInput));
|
||||
}
|
||||
}
|
||||
|
||||
getDefaultValue() {
|
||||
const { filterState, defaultValue } = this.props;
|
||||
if (filterState && typeof filterState.filterVal !== 'undefined') {
|
||||
return filterState.filterVal;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
getOptions() {
|
||||
const optionTags = [];
|
||||
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
||||
@@ -106,6 +114,7 @@ class MultiSelectFilter extends Component {
|
||||
const {
|
||||
style,
|
||||
className,
|
||||
filterState,
|
||||
defaultValue,
|
||||
onFilter,
|
||||
column,
|
||||
@@ -135,7 +144,7 @@ class MultiSelectFilter extends Component {
|
||||
className={ selectClass }
|
||||
onChange={ this.filter }
|
||||
onClick={ e => e.stopPropagation() }
|
||||
defaultValue={ defaultValue !== undefined ? defaultValue : '' }
|
||||
defaultValue={ this.getDefaultValue() }
|
||||
>
|
||||
{ this.getOptions() }
|
||||
</select>
|
||||
@@ -148,6 +157,7 @@ MultiSelectFilter.propTypes = {
|
||||
onFilter: PropTypes.func.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
options: PropTypes.object.isRequired,
|
||||
filterState: PropTypes.object,
|
||||
comparator: PropTypes.oneOf([LIKE, EQ]),
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
@@ -160,6 +170,7 @@ MultiSelectFilter.propTypes = {
|
||||
|
||||
MultiSelectFilter.defaultProps = {
|
||||
defaultValue: [],
|
||||
filterState: {},
|
||||
className: '',
|
||||
withoutEmptyOption: false,
|
||||
comparator: EQ,
|
||||
|
||||
@@ -94,6 +94,28 @@ class NumberFilter extends Component {
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||
}
|
||||
|
||||
getDefaultComparator() {
|
||||
const { defaultValue, filterState } = this.props;
|
||||
if (filterState && filterState.filterVal) {
|
||||
return filterState.filterVal.comparator;
|
||||
}
|
||||
if (defaultValue && defaultValue.comparator) {
|
||||
return defaultValue.comparator;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getDefaultValue() {
|
||||
const { defaultValue, filterState } = this.props;
|
||||
if (filterState && filterState.filterVal) {
|
||||
return filterState.filterVal.number;
|
||||
}
|
||||
if (defaultValue && defaultValue.number) {
|
||||
return defaultValue.number;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getComparatorOptions() {
|
||||
const optionTags = [];
|
||||
const { withoutEmptyComparatorOption } = this.props;
|
||||
@@ -148,7 +170,6 @@ class NumberFilter extends Component {
|
||||
render() {
|
||||
const { isSelected } = this.state;
|
||||
const {
|
||||
defaultValue,
|
||||
column,
|
||||
options,
|
||||
style,
|
||||
@@ -184,7 +205,7 @@ class NumberFilter extends Component {
|
||||
id={ `number-filter-comparator-${column.text}` }
|
||||
className={ `number-filter-comparator form-control ${comparatorClassName}` }
|
||||
onChange={ this.onChangeComparator }
|
||||
defaultValue={ defaultValue ? defaultValue.comparator : '' }
|
||||
defaultValue={ this.getDefaultComparator() }
|
||||
>
|
||||
{ this.getComparatorOptions() }
|
||||
</select>
|
||||
@@ -202,7 +223,7 @@ class NumberFilter extends Component {
|
||||
style={ numberStyle }
|
||||
className={ selectClass }
|
||||
onChange={ this.onChangeNumberSet }
|
||||
defaultValue={ defaultValue ? defaultValue.number : '' }
|
||||
defaultValue={ this.getDefaultValue() }
|
||||
>
|
||||
{ this.getNumberOptions() }
|
||||
</select>
|
||||
@@ -217,7 +238,7 @@ class NumberFilter extends Component {
|
||||
className={ `number-filter-input form-control ${numberClassName}` }
|
||||
placeholder={ placeholder || `Enter ${column.text}...` }
|
||||
onChange={ this.onChangeNumber }
|
||||
defaultValue={ defaultValue ? defaultValue.number : '' }
|
||||
defaultValue={ this.getDefaultValue() }
|
||||
/>
|
||||
</label>
|
||||
}
|
||||
@@ -229,6 +250,7 @@ class NumberFilter extends Component {
|
||||
NumberFilter.propTypes = {
|
||||
onFilter: PropTypes.func.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
filterState: PropTypes.object,
|
||||
options: PropTypes.arrayOf(PropTypes.number),
|
||||
defaultValue: PropTypes.shape({
|
||||
number: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
@@ -273,6 +295,7 @@ NumberFilter.defaultProps = {
|
||||
number: undefined,
|
||||
comparator: ''
|
||||
},
|
||||
filterState: {},
|
||||
withoutEmptyComparatorOption: false,
|
||||
withoutEmptyNumberOption: false,
|
||||
comparators: legalComparators,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint react/require-default-props: 0 */
|
||||
/* eslint no-return-assign: 0 */
|
||||
/* eslint react/no-unused-prop-types: 0 */
|
||||
/* eslint class-methods-use-this: 0 */
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { LIKE, EQ } from '../comparison';
|
||||
@@ -44,7 +45,8 @@ class SelectFilter extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.filter = this.filter.bind(this);
|
||||
const isSelected = getOptionValue(props.options, props.defaultValue) !== undefined;
|
||||
this.options = this.getOptions(props);
|
||||
const isSelected = getOptionValue(this.options, this.getDefaultValue()) !== undefined;
|
||||
this.state = { isSelected };
|
||||
}
|
||||
|
||||
@@ -69,36 +71,36 @@ class SelectFilter extends Component {
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
let needFilter = false;
|
||||
if (this.props.defaultValue !== prevProps.defaultValue) {
|
||||
const {
|
||||
column,
|
||||
onFilter,
|
||||
defaultValue
|
||||
} = this.props;
|
||||
const nextOptions = this.getOptions(this.props);
|
||||
if (defaultValue !== prevProps.defaultValue) {
|
||||
needFilter = true;
|
||||
} else if (!optionsEquals(this.props.options, prevProps.options)) {
|
||||
} else if (!optionsEquals(nextOptions, this.options)) {
|
||||
this.options = nextOptions;
|
||||
needFilter = true;
|
||||
}
|
||||
if (needFilter) {
|
||||
const value = this.selectInput.value;
|
||||
if (value) {
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||
onFilter(column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getOptions() {
|
||||
const optionTags = [];
|
||||
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
||||
if (!withoutEmptyOption) {
|
||||
optionTags.push((
|
||||
<option key="-1" value="">{ placeholder || `Select ${column.text}...` }</option>
|
||||
));
|
||||
getOptions(props) {
|
||||
return typeof props.options === 'function' ? props.options(props.column) : props.options;
|
||||
}
|
||||
|
||||
getDefaultValue() {
|
||||
const { filterState, defaultValue } = this.props;
|
||||
if (filterState && typeof filterState.filterVal !== 'undefined') {
|
||||
return filterState.filterVal;
|
||||
}
|
||||
if (Array.isArray(options)) {
|
||||
options.forEach(({ value, label }) =>
|
||||
optionTags.push(<option key={ value } value={ value }>{ label }</option>));
|
||||
} else {
|
||||
Object.keys(options).forEach(key =>
|
||||
optionTags.push(<option key={ key } value={ key }>{ options[key] }</option>)
|
||||
);
|
||||
}
|
||||
return optionTags;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
cleanFiltered() {
|
||||
@@ -120,6 +122,26 @@ class SelectFilter extends Component {
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
|
||||
renderOptions() {
|
||||
const optionTags = [];
|
||||
const { options } = this;
|
||||
const { placeholder, column, withoutEmptyOption } = this.props;
|
||||
if (!withoutEmptyOption) {
|
||||
optionTags.push((
|
||||
<option key="-1" value="">{ placeholder || `Select ${column.text}...` }</option>
|
||||
));
|
||||
}
|
||||
if (Array.isArray(options)) {
|
||||
options.forEach(({ value, label }) =>
|
||||
optionTags.push(<option key={ value } value={ value }>{ label }</option>));
|
||||
} else {
|
||||
Object.keys(options).forEach(key =>
|
||||
optionTags.push(<option key={ key } value={ key }>{ options[key] }</option>)
|
||||
);
|
||||
}
|
||||
return optionTags;
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
style,
|
||||
@@ -132,6 +154,7 @@ class SelectFilter extends Component {
|
||||
withoutEmptyOption,
|
||||
caseSensitive,
|
||||
getFilter,
|
||||
filterState,
|
||||
...rest
|
||||
} = this.props;
|
||||
|
||||
@@ -152,9 +175,9 @@ class SelectFilter extends Component {
|
||||
className={ selectClass }
|
||||
onChange={ this.filter }
|
||||
onClick={ e => e.stopPropagation() }
|
||||
defaultValue={ defaultValue !== undefined ? defaultValue : '' }
|
||||
defaultValue={ this.getDefaultValue() || '' }
|
||||
>
|
||||
{ this.getOptions() }
|
||||
{ this.renderOptions() }
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
@@ -164,6 +187,7 @@ class SelectFilter extends Component {
|
||||
SelectFilter.propTypes = {
|
||||
onFilter: PropTypes.func.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
filterState: PropTypes.object,
|
||||
options: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
|
||||
comparator: PropTypes.oneOf([LIKE, EQ]),
|
||||
placeholder: PropTypes.string,
|
||||
@@ -177,6 +201,7 @@ SelectFilter.propTypes = {
|
||||
|
||||
SelectFilter.defaultProps = {
|
||||
defaultValue: '',
|
||||
filterState: {},
|
||||
className: '',
|
||||
withoutEmptyOption: false,
|
||||
comparator: EQ,
|
||||
|
||||
@@ -13,8 +13,14 @@ class TextFilter extends Component {
|
||||
this.filter = this.filter.bind(this);
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
this.timeout = null;
|
||||
function getDefaultValue() {
|
||||
if (props.filterState && typeof props.filterState.filterVal !== 'undefined') {
|
||||
return props.filterState.filterVal;
|
||||
}
|
||||
return props.defaultValue;
|
||||
}
|
||||
this.state = {
|
||||
value: props.defaultValue
|
||||
value: getDefaultValue()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,6 +95,7 @@ class TextFilter extends Component {
|
||||
caseSensitive,
|
||||
defaultValue,
|
||||
getFilter,
|
||||
filterState,
|
||||
...rest
|
||||
} = this.props;
|
||||
|
||||
@@ -119,6 +126,7 @@ class TextFilter extends Component {
|
||||
TextFilter.propTypes = {
|
||||
onFilter: PropTypes.func.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
filterState: PropTypes.object,
|
||||
comparator: PropTypes.oneOf([LIKE, EQ]),
|
||||
defaultValue: PropTypes.string,
|
||||
delay: PropTypes.number,
|
||||
@@ -131,6 +139,7 @@ TextFilter.propTypes = {
|
||||
|
||||
TextFilter.defaultProps = {
|
||||
delay: FILTER_DELAY,
|
||||
filterState: {},
|
||||
defaultValue: '',
|
||||
caseSensitive: false
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ export default (
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// let nextData = nextProps.data;
|
||||
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
|
||||
this.doFilter(nextProps, undefined, this.isEmitDataChange);
|
||||
this.doFilter(nextProps, this.isEmitDataChange);
|
||||
} else {
|
||||
this.data = nextProps.data;
|
||||
}
|
||||
@@ -76,12 +76,7 @@ export default (
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let result;
|
||||
if (filter.props.onFilter) {
|
||||
result = filter.props.onFilter(filterVal);
|
||||
}
|
||||
this.doFilter(this.props, result);
|
||||
this.doFilter(this.props);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,11 +90,9 @@ export default (
|
||||
return this.data;
|
||||
}
|
||||
|
||||
doFilter(props, customResult, ignoreEmitDataChange = false) {
|
||||
let result = customResult;
|
||||
|
||||
doFilter(props, ignoreEmitDataChange = false) {
|
||||
const { dataChangeListener, data, columns } = props;
|
||||
result = result || filters(data, columns, _)(this.currFilters);
|
||||
const result = filters(data, columns, _)(this.currFilters);
|
||||
this.data = result;
|
||||
if (dataChangeListener && !ignoreEmitDataChange) {
|
||||
this.isEmitDataChange = true;
|
||||
@@ -115,7 +108,8 @@ export default (
|
||||
<FilterContext.Provider value={ {
|
||||
data: this.data,
|
||||
onFilter: this.onFilter,
|
||||
onExternalFilter: this.onExternalFilter
|
||||
onExternalFilter: this.onExternalFilter,
|
||||
currFilters: this.currFilters
|
||||
} }
|
||||
>
|
||||
{ this.props.children }
|
||||
|
||||
@@ -234,16 +234,28 @@ export const filters = (data, columns, _) => (currFilters) => {
|
||||
let result = data;
|
||||
let filterFn;
|
||||
Object.keys(currFilters).forEach((dataField) => {
|
||||
let currentResult;
|
||||
const filterObj = currFilters[dataField];
|
||||
filterFn = factory(filterObj.filterType);
|
||||
let filterValue;
|
||||
let customFilter;
|
||||
for (let i = 0; i < columns.length; i += 1) {
|
||||
if (columns[i].dataField === dataField) {
|
||||
filterValue = columns[i].filterValue;
|
||||
if (columns[i].filter) {
|
||||
customFilter = columns[i].filter.props.onFilter;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = filterFn(result, dataField, filterObj, filterValue);
|
||||
if (customFilter) {
|
||||
currentResult = customFilter(filterObj.filterVal, result);
|
||||
}
|
||||
if (typeof currentResult === 'undefined') {
|
||||
result = filterFn(result, dataField, filterObj, filterValue);
|
||||
} else {
|
||||
result = currentResult;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('Select Filter', () => {
|
||||
2: 'Unknown'
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
beforeEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
|
||||
@@ -94,7 +94,8 @@ describe('FilterContext', () => {
|
||||
expect(mockBase).toHaveBeenCalledWith({
|
||||
data,
|
||||
onFilter: wrapper.instance().onFilter,
|
||||
onExternalFilter: wrapper.instance().onExternalFilter
|
||||
onExternalFilter: wrapper.instance().onExternalFilter,
|
||||
currFilters: wrapper.instance().currFilters
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -103,7 +104,6 @@ describe('FilterContext', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(shallowContext(true));
|
||||
wrapper.render();
|
||||
wrapper.instance().currFilters = { price: { filterVal: 20, filterType: FILTER_TYPE.TEXT } };
|
||||
});
|
||||
|
||||
it('should pass original data without internal filtering', () => {
|
||||
@@ -111,7 +111,8 @@ describe('FilterContext', () => {
|
||||
expect(mockBase).toHaveBeenCalledWith({
|
||||
data,
|
||||
onFilter: wrapper.instance().onFilter,
|
||||
onExternalFilter: wrapper.instance().onExternalFilter
|
||||
onExternalFilter: wrapper.instance().onExternalFilter,
|
||||
currFilters: wrapper.instance().currFilters
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -228,33 +229,7 @@ describe('FilterContext', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('if filter.props.onFilter is defined', () => {
|
||||
const filterVal = '3';
|
||||
const onFilter = jest.fn();
|
||||
const customColumns = columns.map((column, i) => {
|
||||
if (i === 1) {
|
||||
return {
|
||||
...column,
|
||||
filter: textFilter({ onFilter })
|
||||
};
|
||||
}
|
||||
return column;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(shallowContext(false, customColumns));
|
||||
wrapper.render();
|
||||
instance = wrapper.instance();
|
||||
});
|
||||
|
||||
it('should call filter.props.onFilter correctly', () => {
|
||||
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(onFilter).toHaveBeenCalledTimes(1);
|
||||
expect(onFilter).toHaveBeenCalledWith(filterVal);
|
||||
});
|
||||
});
|
||||
|
||||
describe('if filter.props.onFilter is defined and return an undefined data', () => {
|
||||
describe('if filter.props.onFilter is defined and return data', () => {
|
||||
const mockReturn = [{
|
||||
id: 1,
|
||||
name: 'A'
|
||||
@@ -280,7 +255,7 @@ describe('FilterContext', () => {
|
||||
it('should call filter.props.onFilter correctly', () => {
|
||||
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(onFilter).toHaveBeenCalledTimes(1);
|
||||
expect(onFilter).toHaveBeenCalledWith(filterVal);
|
||||
expect(onFilter).toHaveBeenCalledWith(filterVal, data);
|
||||
});
|
||||
|
||||
it('should set data correctly', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-paginator",
|
||||
"version": "2.0.7",
|
||||
"version": "2.0.8",
|
||||
"description": "it's the pagination addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.react-bootstrap-table-page-btns-ul {
|
||||
float: right;
|
||||
margin-top: 0px;
|
||||
margin-top: 0px !important;
|
||||
}
|
||||
|
||||
.react-bootstrap-table-pagination-list-hidden {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table-next",
|
||||
"version": "3.1.6",
|
||||
"version": "3.1.9",
|
||||
"description": "Next generation of react-bootstrap-table",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -91,6 +91,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
||||
sortOrder={ this.props.sortOrder }
|
||||
onSort={ this.props.onSort }
|
||||
onFilter={ this.props.onFilter }
|
||||
currFilters={ this.props.currFilters }
|
||||
onExternalFilter={ this.props.onExternalFilter }
|
||||
selectRow={ selectRow }
|
||||
expandRow={ expandRow }
|
||||
@@ -190,6 +191,7 @@ BootstrapTable.propTypes = {
|
||||
Const.INDICATOR_POSITION_LEFT,
|
||||
Const.INDICATOR_POSITION_RIGHT
|
||||
]),
|
||||
className: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
parentClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
|
||||
}),
|
||||
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||
|
||||
1
packages/react-bootstrap-table2/src/cell.js
vendored
1
packages/react-bootstrap-table2/src/cell.js
vendored
@@ -28,6 +28,7 @@ class Cell extends eventDelegater(Component) {
|
||||
shouldUpdate =
|
||||
(nextProps.column.formatter ? !_.isEqual(this.props.row, nextProps.row) : false) ||
|
||||
this.props.column.hidden !== nextProps.column.hidden ||
|
||||
this.props.column.isDummyField !== nextProps.column.isDummyField ||
|
||||
this.props.rowIndex !== nextProps.rowIndex ||
|
||||
this.props.columnIndex !== nextProps.columnIndex ||
|
||||
this.props.className !== nextProps.className ||
|
||||
|
||||
@@ -91,6 +91,13 @@ const withContext = Base =>
|
||||
this.PaginationContext = nextProps.pagination.createContext(
|
||||
this.isRemotePagination, this.handleRemotePageChange);
|
||||
}
|
||||
if (!nextProps.cellEdit && this.props.cellEdit) {
|
||||
this.CellEditContext = null;
|
||||
}
|
||||
if (nextProps.cellEdit && !this.props.cellEdit) {
|
||||
this.CellEditContext = nextProps.cellEdit.createContext(
|
||||
_, dataOperator, this.isRemoteCellEdit, this.handleRemoteCellChange);
|
||||
}
|
||||
}
|
||||
|
||||
renderBase() {
|
||||
|
||||
@@ -18,6 +18,7 @@ const HeaderCell = (props) => {
|
||||
sortOrder,
|
||||
isLastSorting,
|
||||
onFilter,
|
||||
currFilters,
|
||||
onExternalFilter
|
||||
} = props;
|
||||
|
||||
@@ -99,7 +100,14 @@ const HeaderCell = (props) => {
|
||||
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||
filterElm = filterRenderer(onCustomFilter, column);
|
||||
} else if (filter) {
|
||||
filterElm = <filter.Filter { ...filter.props } onFilter={ onFilter } column={ column } />;
|
||||
filterElm = (
|
||||
<filter.Filter
|
||||
{ ...filter.props }
|
||||
filterState={ currFilters[column.dataField] }
|
||||
onFilter={ onFilter }
|
||||
column={ column }
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const children = headerFormatter ?
|
||||
@@ -153,7 +161,8 @@ HeaderCell.propTypes = {
|
||||
validator: PropTypes.func,
|
||||
filter: PropTypes.object,
|
||||
filterRenderer: PropTypes.func,
|
||||
filterValue: PropTypes.func
|
||||
filterValue: PropTypes.func,
|
||||
searchable: PropTypes.bool
|
||||
}).isRequired,
|
||||
index: PropTypes.number.isRequired,
|
||||
onSort: PropTypes.func,
|
||||
@@ -162,6 +171,7 @@ HeaderCell.propTypes = {
|
||||
sortCaret: PropTypes.func,
|
||||
isLastSorting: PropTypes.bool,
|
||||
onFilter: PropTypes.func,
|
||||
currFilters: PropTypes.object,
|
||||
onExternalFilter: PropTypes.func
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ const Header = (props) => {
|
||||
sortField,
|
||||
sortOrder,
|
||||
selectRow,
|
||||
currFilters,
|
||||
onExternalFilter,
|
||||
expandRow
|
||||
} = props;
|
||||
@@ -50,6 +51,7 @@ const Header = (props) => {
|
||||
onSort={ onSort }
|
||||
sorting={ currSort }
|
||||
onFilter={ onFilter }
|
||||
currFilters={ currFilters }
|
||||
onExternalFilter={ onExternalFilter }
|
||||
sortOrder={ sortOrder }
|
||||
isLastSorting={ isLastSorting }
|
||||
@@ -89,6 +91,7 @@ Header.propTypes = {
|
||||
sortField: PropTypes.string,
|
||||
sortOrder: PropTypes.string,
|
||||
selectRow: PropTypes.object,
|
||||
currFilters: PropTypes.object,
|
||||
onExternalFilter: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
expandRow: PropTypes.object
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import cs from 'classnames';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
|
||||
const ExpandRow = ({ children, expanded, onClosed, ...rest }) => (
|
||||
const ExpandRow = ({ children, expanded, onClosed, className, ...rest }) => (
|
||||
<tr>
|
||||
<td className="reset-expansion-style" { ...rest }>
|
||||
<td className={ cs('reset-expansion-style', className) } { ...rest }>
|
||||
<CSSTransition
|
||||
appear
|
||||
in={ expanded }
|
||||
@@ -25,13 +26,15 @@ const ExpandRow = ({ children, expanded, onClosed, ...rest }) => (
|
||||
ExpandRow.propTypes = {
|
||||
children: PropTypes.node,
|
||||
expanded: PropTypes.bool,
|
||||
onClosed: PropTypes.func
|
||||
onClosed: PropTypes.func,
|
||||
className: PropTypes.string
|
||||
};
|
||||
|
||||
ExpandRow.defaultProps = {
|
||||
children: null,
|
||||
expanded: false,
|
||||
onClosed: null
|
||||
onClosed: null,
|
||||
className: ''
|
||||
};
|
||||
|
||||
export default ExpandRow;
|
||||
|
||||
@@ -8,6 +8,7 @@ import ExpansionContext from '../contexts/row-expand-context';
|
||||
export default (Component) => {
|
||||
const renderWithExpansion = (props, expandRow) => {
|
||||
let parentClassName = '';
|
||||
let className = '';
|
||||
const key = props.value;
|
||||
|
||||
const expanded = _.contains(expandRow.expanded, key);
|
||||
@@ -17,6 +18,10 @@ export default (Component) => {
|
||||
parentClassName = _.isFunction(expandRow.parentClassName) ?
|
||||
expandRow.parentClassName(expanded, props.row, props.rowIndex) :
|
||||
(expandRow.parentClassName || '');
|
||||
|
||||
className = _.isFunction(expandRow.className) ?
|
||||
expandRow.className(expanded, props.row, props.rowIndex) :
|
||||
(expandRow.className || '');
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -33,6 +38,7 @@ export default (Component) => {
|
||||
colSpan={ props.visibleColumnSize }
|
||||
expanded={ expanded }
|
||||
onClosed={ () => expandRow.onClosed(key) }
|
||||
className={ className }
|
||||
>
|
||||
{ expandRow.renderer(props.row, props.rowIndex) }
|
||||
</ExpandRow> : null
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Const from '../const';
|
||||
|
||||
export const typeConvert = (type, value) => {
|
||||
if (!type || type === Const.TYPE_STRING) {
|
||||
if (type === Const.TYPE_STRING) {
|
||||
return String(value);
|
||||
} else if (type === Const.TYPE_NUMBER) {
|
||||
return Number(value);
|
||||
|
||||
@@ -728,7 +728,9 @@ describe('HeaderCell', () => {
|
||||
Filter
|
||||
}
|
||||
};
|
||||
wrapper = shallow(<HeaderCell column={ column } index={ index } onFilter={ onFilter } />);
|
||||
wrapper = shallow(
|
||||
<HeaderCell column={ column } index={ index } onFilter={ onFilter } currFilters={ {} } />
|
||||
);
|
||||
});
|
||||
|
||||
it('should render successfully', () => {
|
||||
|
||||
Reference in New Issue
Block a user