mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 21:50:07 +00:00
Compare commits
26 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
110744f4cb | ||
|
|
47848e7f34 | ||
|
|
1a44ce0ea6 | ||
|
|
08ec8a9f65 | ||
|
|
27387c2a69 | ||
|
|
05b50ac71a | ||
|
|
9b6d9904e7 | ||
|
|
4de565b759 | ||
|
|
c53d2612d4 | ||
|
|
0c2863d63c | ||
|
|
a534d525c9 | ||
|
|
856e63d524 | ||
|
|
c59b963436 | ||
|
|
b50dc95e06 | ||
|
|
2619a1e424 | ||
|
|
423769c134 | ||
|
|
6530ff1570 | ||
|
|
9af61b54b1 | ||
|
|
72f7333a34 | ||
|
|
64c113da26 | ||
|
|
db22bb9adb | ||
|
|
d7e1f1dfd0 | ||
|
|
c277c8139e | ||
|
|
ec4864da5c | ||
|
|
92f1449177 | ||
|
|
46258b0264 |
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
|
# react-bootstrap-table2
|
||||||
|
|
||||||
[](https://travis-ci.org/react-bootstrap-table/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.
|
> 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.
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
|
|||||||
@@ -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';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
@@ -140,7 +140,7 @@ const columns = [
|
|||||||
text: 'Job Type',
|
text: 'Job Type',
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.SELECT,
|
type: Type.SELECT,
|
||||||
getOptions: () => [.....]
|
getOptions: (setOptions, { row, column }) => [.....]
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ const columns = [
|
|||||||
text: 'Job Type',
|
text: 'Job Type',
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.SELECT,
|
type: Type.SELECT,
|
||||||
getOptions: (setOptions) => {
|
getOptions: (setOptions, { row, column }) => {
|
||||||
setTimeout(() => setOptions([...]), 1500);
|
setTimeout(() => setOptions([...]), 1500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-editor",
|
"name": "react-bootstrap-table2-editor",
|
||||||
"version": "1.2.4",
|
"version": "1.3.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": {
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -8,7 +8,13 @@ class DropDownEditor extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
let options = props.options;
|
let options = props.options;
|
||||||
if (props.getOptions) {
|
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 };
|
this.state = { options };
|
||||||
}
|
}
|
||||||
@@ -54,6 +60,8 @@ class DropDownEditor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DropDownEditor.propTypes = {
|
DropDownEditor.propTypes = {
|
||||||
|
row: PropTypes.object.isRequired,
|
||||||
|
column: PropTypes.object.isRequired,
|
||||||
defaultValue: PropTypes.oneOfType([
|
defaultValue: PropTypes.oneOfType([
|
||||||
PropTypes.string,
|
PropTypes.string,
|
||||||
PropTypes.number
|
PropTypes.number
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ export default (_, onStartEdit) =>
|
|||||||
if (_.isFunction(column.editorRenderer)) {
|
if (_.isFunction(column.editorRenderer)) {
|
||||||
editor = column.editorRenderer(editorProps, value, row, column, rowIndex, columnIndex);
|
editor = column.editorRenderer(editorProps, value, row, column, rowIndex, columnIndex);
|
||||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
|
} 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) {
|
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
|
||||||
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
||||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
|
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
|
||||||
|
|||||||
123
packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-with-data-type.js
vendored
Normal file
123
packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-with-data-type.js
vendored
Normal 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>
|
||||||
|
);
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint no-console: 0 */
|
||||||
/* eslint react/prefer-stateless-function: 0 */
|
/* eslint react/prefer-stateless-function: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
@@ -25,22 +26,26 @@ const columns = [{
|
|||||||
text: 'Job Type1',
|
text: 'Job Type1',
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.SELECT,
|
type: Type.SELECT,
|
||||||
getOptions: () => [{
|
getOptions: (setOptions, { row, column }) => {
|
||||||
value: 'A',
|
console.log(`current editing row id: ${row.id}`);
|
||||||
label: 'A'
|
console.log(`current editing column: ${column.dataField}`);
|
||||||
}, {
|
return [{
|
||||||
value: 'B',
|
value: 'A',
|
||||||
label: 'B'
|
label: 'A'
|
||||||
}, {
|
}, {
|
||||||
value: 'C',
|
value: 'B',
|
||||||
label: 'C'
|
label: 'B'
|
||||||
}, {
|
}, {
|
||||||
value: 'D',
|
value: 'C',
|
||||||
label: 'D'
|
label: 'C'
|
||||||
}, {
|
}, {
|
||||||
value: 'E',
|
value: 'D',
|
||||||
label: 'E'
|
label: 'D'
|
||||||
}]
|
}, {
|
||||||
|
value: 'E',
|
||||||
|
label: 'E'
|
||||||
|
}];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
dataField: 'type2',
|
dataField: 'type2',
|
||||||
@@ -88,22 +93,26 @@ const columns = [{
|
|||||||
text: 'Job Type1',
|
text: 'Job Type1',
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.SELECT,
|
type: Type.SELECT,
|
||||||
getOptions: () => [{
|
getOptions: (setOptions, { row, column }) => {
|
||||||
value: 'A',
|
console.log(\`current editing row id: $\{row.id}\`);
|
||||||
label: 'A'
|
console.log(\`current editing column: $\{column.dataField}\`);
|
||||||
}, {
|
return [{
|
||||||
value: 'B',
|
value: 'A',
|
||||||
label: 'B'
|
label: 'A'
|
||||||
}, {
|
}, {
|
||||||
value: 'C',
|
value: 'B',
|
||||||
label: 'C'
|
label: 'B'
|
||||||
}, {
|
}, {
|
||||||
value: 'D',
|
value: 'C',
|
||||||
label: 'D'
|
label: 'C'
|
||||||
}, {
|
}, {
|
||||||
value: 'E',
|
value: 'D',
|
||||||
label: 'E'
|
label: 'D'
|
||||||
}]
|
}, {
|
||||||
|
value: 'E',
|
||||||
|
label: 'E'
|
||||||
|
}];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
dataField: 'type2',
|
dataField: 'type2',
|
||||||
|
|||||||
@@ -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, data) => {
|
||||||
products.filter(product => product.price == filterVal);
|
if (filterVal) {
|
||||||
|
return data.filter(product => product.price == filterVal);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
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, data) => {
|
||||||
products.filter(product => product.price == filterVal);
|
if (filterVal) {
|
||||||
|
return data.filter(product => product.price == filterVal);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
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 a eq price filter</h2>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
keyField="id"
|
||||||
data={ products }
|
data={ products }
|
||||||
|
|||||||
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>
|
||||||
|
);
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
106
packages/react-bootstrap-table2-example/examples/row-expand/parent-row-classname.js
vendored
Normal file
106
packages/react-bootstrap-table2-example/examples/row-expand/parent-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 = {
|
||||||
|
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>
|
||||||
|
);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.27",
|
"version": "1.0.29",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -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()))
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ 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';
|
||||||
@@ -164,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';
|
||||||
@@ -208,6 +210,7 @@ import BasicColumnToggle from 'examples/column-toggle';
|
|||||||
import DefaultVisibility from 'examples/column-toggle/default-visibility';
|
import DefaultVisibility from 'examples/column-toggle/default-visibility';
|
||||||
import StylingColumnToggle from 'examples/column-toggle/styling-toggle-list';
|
import StylingColumnToggle from 'examples/column-toggle/styling-toggle-list';
|
||||||
import CustomToggleList from 'examples/column-toggle/custom-toggle-list';
|
import CustomToggleList from 'examples/column-toggle/custom-toggle-list';
|
||||||
|
import ColumnToggleWithFilter from 'examples/column-toggle/column-toggle-with-filter';
|
||||||
|
|
||||||
// loading overlay
|
// loading overlay
|
||||||
import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay';
|
import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay';
|
||||||
@@ -377,7 +380,8 @@ storiesOf('Cell Editing', module)
|
|||||||
.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())
|
||||||
@@ -412,7 +416,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())
|
||||||
@@ -439,7 +444,7 @@ storiesOf('Table Search', module)
|
|||||||
.add('Default Search Table', () => <DefaultSearch />)
|
.add('Default Search Table', () => <DefaultSearch />)
|
||||||
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
||||||
.add('Fully Custom Search', () => <FullyCustomSearch />)
|
.add('Fully Custom Search', () => <FullyCustomSearch />)
|
||||||
.add('Search Fromatted Value', () => <SearchFormattedData />)
|
.add('Search Formatted Value', () => <SearchFormattedData />)
|
||||||
.add('Custom Search Value', () => <CustomSearchValue />);
|
.add('Custom Search Value', () => <CustomSearchValue />);
|
||||||
|
|
||||||
storiesOf('Column Toggle', module)
|
storiesOf('Column Toggle', module)
|
||||||
@@ -447,7 +452,8 @@ storiesOf('Column Toggle', module)
|
|||||||
.add('Basic Column Toggle', () => <BasicColumnToggle />)
|
.add('Basic Column Toggle', () => <BasicColumnToggle />)
|
||||||
.add('Default Visibility', () => <DefaultVisibility />)
|
.add('Default Visibility', () => <DefaultVisibility />)
|
||||||
.add('Styling Column Toggle', () => <StylingColumnToggle />)
|
.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)
|
storiesOf('Export CSV', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.parent-expand-foo {
|
||||||
|
background-color: coral;
|
||||||
|
}
|
||||||
|
|
||||||
|
.parent-expand-bar {
|
||||||
|
background-color: aqua;
|
||||||
|
}
|
||||||
@@ -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";
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-filter",
|
"name": "react-bootstrap-table2-filter",
|
||||||
"version": "1.1.10",
|
"version": "1.1.11",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -83,14 +83,27 @@ class DateFilter extends Component {
|
|||||||
return optionTags;
|
return optionTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultDate() {
|
getDefaultComparator() {
|
||||||
let defaultDate = '';
|
const { defaultValue, filterState } = this.props;
|
||||||
const { defaultValue } = this.props;
|
if (filterState && filterState.filterVal) {
|
||||||
if (defaultValue && defaultValue.date) {
|
return filterState.filterVal.comparator;
|
||||||
// Set the appropriate format for the input type=date, i.e. "YYYY-MM-DD"
|
|
||||||
defaultDate = dateParser(new Date(defaultValue.date));
|
|
||||||
}
|
}
|
||||||
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) {
|
applyFilter(value, comparator, isInitial) {
|
||||||
@@ -122,8 +135,7 @@ class DateFilter extends Component {
|
|||||||
dateStyle,
|
dateStyle,
|
||||||
className,
|
className,
|
||||||
comparatorClassName,
|
comparatorClassName,
|
||||||
dateClassName,
|
dateClassName
|
||||||
defaultValue
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -143,7 +155,7 @@ class DateFilter extends Component {
|
|||||||
style={ comparatorStyle }
|
style={ comparatorStyle }
|
||||||
className={ `date-filter-comparator form-control ${comparatorClassName}` }
|
className={ `date-filter-comparator form-control ${comparatorClassName}` }
|
||||||
onChange={ this.onChangeComparator }
|
onChange={ this.onChangeComparator }
|
||||||
defaultValue={ defaultValue ? defaultValue.comparator : '' }
|
defaultValue={ this.getDefaultComparator() }
|
||||||
>
|
>
|
||||||
{ this.getComparatorOptions() }
|
{ this.getComparatorOptions() }
|
||||||
</select>
|
</select>
|
||||||
@@ -169,6 +181,7 @@ class DateFilter extends Component {
|
|||||||
DateFilter.propTypes = {
|
DateFilter.propTypes = {
|
||||||
onFilter: PropTypes.func.isRequired,
|
onFilter: PropTypes.func.isRequired,
|
||||||
column: PropTypes.object.isRequired,
|
column: PropTypes.object.isRequired,
|
||||||
|
filterState: PropTypes.object,
|
||||||
delay: PropTypes.number,
|
delay: PropTypes.number,
|
||||||
defaultValue: PropTypes.shape({
|
defaultValue: PropTypes.shape({
|
||||||
date: PropTypes.oneOfType([PropTypes.object]),
|
date: PropTypes.oneOfType([PropTypes.object]),
|
||||||
@@ -210,6 +223,7 @@ DateFilter.defaultProps = {
|
|||||||
date: undefined,
|
date: undefined,
|
||||||
comparator: ''
|
comparator: ''
|
||||||
},
|
},
|
||||||
|
filterState: {},
|
||||||
withoutEmptyComparatorOption: false,
|
withoutEmptyComparatorOption: false,
|
||||||
comparators: legalComparators,
|
comparators: legalComparators,
|
||||||
placeholder: undefined,
|
placeholder: undefined,
|
||||||
|
|||||||
@@ -65,10 +65,18 @@ class MultiSelectFilter extends Component {
|
|||||||
needFilter = true;
|
needFilter = true;
|
||||||
}
|
}
|
||||||
if (needFilter) {
|
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() {
|
getOptions() {
|
||||||
const optionTags = [];
|
const optionTags = [];
|
||||||
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
||||||
@@ -106,6 +114,7 @@ class MultiSelectFilter extends Component {
|
|||||||
const {
|
const {
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
|
filterState,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
onFilter,
|
onFilter,
|
||||||
column,
|
column,
|
||||||
@@ -135,7 +144,7 @@ class MultiSelectFilter extends Component {
|
|||||||
className={ selectClass }
|
className={ selectClass }
|
||||||
onChange={ this.filter }
|
onChange={ this.filter }
|
||||||
onClick={ e => e.stopPropagation() }
|
onClick={ e => e.stopPropagation() }
|
||||||
defaultValue={ defaultValue !== undefined ? defaultValue : '' }
|
defaultValue={ this.getDefaultValue() }
|
||||||
>
|
>
|
||||||
{ this.getOptions() }
|
{ this.getOptions() }
|
||||||
</select>
|
</select>
|
||||||
@@ -148,6 +157,7 @@ MultiSelectFilter.propTypes = {
|
|||||||
onFilter: PropTypes.func.isRequired,
|
onFilter: PropTypes.func.isRequired,
|
||||||
column: PropTypes.object.isRequired,
|
column: PropTypes.object.isRequired,
|
||||||
options: PropTypes.object.isRequired,
|
options: PropTypes.object.isRequired,
|
||||||
|
filterState: PropTypes.object,
|
||||||
comparator: PropTypes.oneOf([LIKE, EQ]),
|
comparator: PropTypes.oneOf([LIKE, EQ]),
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
style: PropTypes.object,
|
style: PropTypes.object,
|
||||||
@@ -160,6 +170,7 @@ MultiSelectFilter.propTypes = {
|
|||||||
|
|
||||||
MultiSelectFilter.defaultProps = {
|
MultiSelectFilter.defaultProps = {
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
|
filterState: {},
|
||||||
className: '',
|
className: '',
|
||||||
withoutEmptyOption: false,
|
withoutEmptyOption: false,
|
||||||
comparator: EQ,
|
comparator: EQ,
|
||||||
|
|||||||
@@ -94,6 +94,28 @@ class NumberFilter extends Component {
|
|||||||
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
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() {
|
getComparatorOptions() {
|
||||||
const optionTags = [];
|
const optionTags = [];
|
||||||
const { withoutEmptyComparatorOption } = this.props;
|
const { withoutEmptyComparatorOption } = this.props;
|
||||||
@@ -148,7 +170,6 @@ class NumberFilter extends Component {
|
|||||||
render() {
|
render() {
|
||||||
const { isSelected } = this.state;
|
const { isSelected } = this.state;
|
||||||
const {
|
const {
|
||||||
defaultValue,
|
|
||||||
column,
|
column,
|
||||||
options,
|
options,
|
||||||
style,
|
style,
|
||||||
@@ -184,7 +205,7 @@ class NumberFilter extends Component {
|
|||||||
id={ `number-filter-comparator-${column.text}` }
|
id={ `number-filter-comparator-${column.text}` }
|
||||||
className={ `number-filter-comparator form-control ${comparatorClassName}` }
|
className={ `number-filter-comparator form-control ${comparatorClassName}` }
|
||||||
onChange={ this.onChangeComparator }
|
onChange={ this.onChangeComparator }
|
||||||
defaultValue={ defaultValue ? defaultValue.comparator : '' }
|
defaultValue={ this.getDefaultComparator() }
|
||||||
>
|
>
|
||||||
{ this.getComparatorOptions() }
|
{ this.getComparatorOptions() }
|
||||||
</select>
|
</select>
|
||||||
@@ -202,7 +223,7 @@ class NumberFilter extends Component {
|
|||||||
style={ numberStyle }
|
style={ numberStyle }
|
||||||
className={ selectClass }
|
className={ selectClass }
|
||||||
onChange={ this.onChangeNumberSet }
|
onChange={ this.onChangeNumberSet }
|
||||||
defaultValue={ defaultValue ? defaultValue.number : '' }
|
defaultValue={ this.getDefaultValue() }
|
||||||
>
|
>
|
||||||
{ this.getNumberOptions() }
|
{ this.getNumberOptions() }
|
||||||
</select>
|
</select>
|
||||||
@@ -217,7 +238,7 @@ class NumberFilter extends Component {
|
|||||||
className={ `number-filter-input form-control ${numberClassName}` }
|
className={ `number-filter-input form-control ${numberClassName}` }
|
||||||
placeholder={ placeholder || `Enter ${column.text}...` }
|
placeholder={ placeholder || `Enter ${column.text}...` }
|
||||||
onChange={ this.onChangeNumber }
|
onChange={ this.onChangeNumber }
|
||||||
defaultValue={ defaultValue ? defaultValue.number : '' }
|
defaultValue={ this.getDefaultValue() }
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
}
|
}
|
||||||
@@ -229,6 +250,7 @@ class NumberFilter extends Component {
|
|||||||
NumberFilter.propTypes = {
|
NumberFilter.propTypes = {
|
||||||
onFilter: PropTypes.func.isRequired,
|
onFilter: PropTypes.func.isRequired,
|
||||||
column: PropTypes.object.isRequired,
|
column: PropTypes.object.isRequired,
|
||||||
|
filterState: PropTypes.object,
|
||||||
options: PropTypes.arrayOf(PropTypes.number),
|
options: PropTypes.arrayOf(PropTypes.number),
|
||||||
defaultValue: PropTypes.shape({
|
defaultValue: PropTypes.shape({
|
||||||
number: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
number: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
@@ -273,6 +295,7 @@ NumberFilter.defaultProps = {
|
|||||||
number: undefined,
|
number: undefined,
|
||||||
comparator: ''
|
comparator: ''
|
||||||
},
|
},
|
||||||
|
filterState: {},
|
||||||
withoutEmptyComparatorOption: false,
|
withoutEmptyComparatorOption: false,
|
||||||
withoutEmptyNumberOption: false,
|
withoutEmptyNumberOption: false,
|
||||||
comparators: legalComparators,
|
comparators: legalComparators,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class SelectFilter extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.filter = this.filter.bind(this);
|
this.filter = this.filter.bind(this);
|
||||||
const isSelected = getOptionValue(props.options, props.defaultValue) !== undefined;
|
const isSelected = getOptionValue(props.options, this.getDefaultValue()) !== undefined;
|
||||||
this.state = { isSelected };
|
this.state = { isSelected };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +82,14 @@ class SelectFilter extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDefaultValue() {
|
||||||
|
const { filterState, defaultValue } = this.props;
|
||||||
|
if (filterState && typeof filterState.filterVal !== 'undefined') {
|
||||||
|
return filterState.filterVal;
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
getOptions() {
|
getOptions() {
|
||||||
const optionTags = [];
|
const optionTags = [];
|
||||||
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
||||||
@@ -132,6 +140,7 @@ class SelectFilter extends Component {
|
|||||||
withoutEmptyOption,
|
withoutEmptyOption,
|
||||||
caseSensitive,
|
caseSensitive,
|
||||||
getFilter,
|
getFilter,
|
||||||
|
filterState,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -152,7 +161,7 @@ class SelectFilter extends Component {
|
|||||||
className={ selectClass }
|
className={ selectClass }
|
||||||
onChange={ this.filter }
|
onChange={ this.filter }
|
||||||
onClick={ e => e.stopPropagation() }
|
onClick={ e => e.stopPropagation() }
|
||||||
defaultValue={ defaultValue !== undefined ? defaultValue : '' }
|
defaultValue={ this.getDefaultValue() || '' }
|
||||||
>
|
>
|
||||||
{ this.getOptions() }
|
{ this.getOptions() }
|
||||||
</select>
|
</select>
|
||||||
@@ -164,6 +173,7 @@ class SelectFilter extends Component {
|
|||||||
SelectFilter.propTypes = {
|
SelectFilter.propTypes = {
|
||||||
onFilter: PropTypes.func.isRequired,
|
onFilter: PropTypes.func.isRequired,
|
||||||
column: PropTypes.object.isRequired,
|
column: PropTypes.object.isRequired,
|
||||||
|
filterState: PropTypes.object,
|
||||||
options: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
|
options: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
|
||||||
comparator: PropTypes.oneOf([LIKE, EQ]),
|
comparator: PropTypes.oneOf([LIKE, EQ]),
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
@@ -177,6 +187,7 @@ SelectFilter.propTypes = {
|
|||||||
|
|
||||||
SelectFilter.defaultProps = {
|
SelectFilter.defaultProps = {
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
|
filterState: {},
|
||||||
className: '',
|
className: '',
|
||||||
withoutEmptyOption: false,
|
withoutEmptyOption: false,
|
||||||
comparator: EQ,
|
comparator: EQ,
|
||||||
|
|||||||
@@ -13,8 +13,14 @@ class TextFilter extends Component {
|
|||||||
this.filter = this.filter.bind(this);
|
this.filter = this.filter.bind(this);
|
||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
|
function getDefaultValue() {
|
||||||
|
if (props.filterState && typeof props.filterState.filterVal !== 'undefined') {
|
||||||
|
return props.filterState.filterVal;
|
||||||
|
}
|
||||||
|
return props.defaultValue;
|
||||||
|
}
|
||||||
this.state = {
|
this.state = {
|
||||||
value: props.defaultValue
|
value: getDefaultValue()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +95,7 @@ class TextFilter extends Component {
|
|||||||
caseSensitive,
|
caseSensitive,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
getFilter,
|
getFilter,
|
||||||
|
filterState,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -119,6 +126,7 @@ class TextFilter extends Component {
|
|||||||
TextFilter.propTypes = {
|
TextFilter.propTypes = {
|
||||||
onFilter: PropTypes.func.isRequired,
|
onFilter: PropTypes.func.isRequired,
|
||||||
column: PropTypes.object.isRequired,
|
column: PropTypes.object.isRequired,
|
||||||
|
filterState: PropTypes.object,
|
||||||
comparator: PropTypes.oneOf([LIKE, EQ]),
|
comparator: PropTypes.oneOf([LIKE, EQ]),
|
||||||
defaultValue: PropTypes.string,
|
defaultValue: PropTypes.string,
|
||||||
delay: PropTypes.number,
|
delay: PropTypes.number,
|
||||||
@@ -131,6 +139,7 @@ TextFilter.propTypes = {
|
|||||||
|
|
||||||
TextFilter.defaultProps = {
|
TextFilter.defaultProps = {
|
||||||
delay: FILTER_DELAY,
|
delay: FILTER_DELAY,
|
||||||
|
filterState: {},
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
caseSensitive: false
|
caseSensitive: false
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export default (
|
|||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
// let nextData = nextProps.data;
|
// let nextData = nextProps.data;
|
||||||
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
|
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
|
||||||
this.doFilter(nextProps, undefined, this.isEmitDataChange);
|
this.doFilter(nextProps, this.isEmitDataChange);
|
||||||
} else {
|
} else {
|
||||||
this.data = nextProps.data;
|
this.data = nextProps.data;
|
||||||
}
|
}
|
||||||
@@ -76,12 +76,7 @@ export default (
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.doFilter(this.props);
|
||||||
let result;
|
|
||||||
if (filter.props.onFilter) {
|
|
||||||
result = filter.props.onFilter(filterVal);
|
|
||||||
}
|
|
||||||
this.doFilter(this.props, result);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +90,9 @@ export default (
|
|||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
doFilter(props, customResult, ignoreEmitDataChange = false) {
|
doFilter(props, ignoreEmitDataChange = false) {
|
||||||
let result = customResult;
|
|
||||||
|
|
||||||
const { dataChangeListener, data, columns } = props;
|
const { dataChangeListener, data, columns } = props;
|
||||||
result = result || filters(data, columns, _)(this.currFilters);
|
const result = filters(data, columns, _)(this.currFilters);
|
||||||
this.data = result;
|
this.data = result;
|
||||||
if (dataChangeListener && !ignoreEmitDataChange) {
|
if (dataChangeListener && !ignoreEmitDataChange) {
|
||||||
this.isEmitDataChange = true;
|
this.isEmitDataChange = true;
|
||||||
@@ -115,7 +108,8 @@ export default (
|
|||||||
<FilterContext.Provider value={ {
|
<FilterContext.Provider value={ {
|
||||||
data: this.data,
|
data: this.data,
|
||||||
onFilter: this.onFilter,
|
onFilter: this.onFilter,
|
||||||
onExternalFilter: this.onExternalFilter
|
onExternalFilter: this.onExternalFilter,
|
||||||
|
currFilters: this.currFilters
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
{ this.props.children }
|
{ this.props.children }
|
||||||
|
|||||||
@@ -237,13 +237,21 @@ export const filters = (data, columns, _) => (currFilters) => {
|
|||||||
const filterObj = currFilters[dataField];
|
const filterObj = currFilters[dataField];
|
||||||
filterFn = factory(filterObj.filterType);
|
filterFn = factory(filterObj.filterType);
|
||||||
let filterValue;
|
let filterValue;
|
||||||
|
let customFilter;
|
||||||
for (let i = 0; i < columns.length; i += 1) {
|
for (let i = 0; i < columns.length; i += 1) {
|
||||||
if (columns[i].dataField === dataField) {
|
if (columns[i].dataField === dataField) {
|
||||||
filterValue = columns[i].filterValue;
|
filterValue = columns[i].filterValue;
|
||||||
|
if (columns[i].filter) {
|
||||||
|
customFilter = columns[i].filter.props.onFilter;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = filterFn(result, dataField, filterObj, filterValue);
|
if (customFilter) {
|
||||||
|
result = customFilter(filterObj.filterVal, result);
|
||||||
|
} else {
|
||||||
|
result = filterFn(result, dataField, filterObj, filterValue);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe('Select Filter', () => {
|
|||||||
2: 'Unknown'
|
2: 'Unknown'
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(() => {
|
beforeEach(() => {
|
||||||
onFilter.reset();
|
onFilter.reset();
|
||||||
onFilterFirstReturn.reset();
|
onFilterFirstReturn.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ describe('FilterContext', () => {
|
|||||||
expect(mockBase).toHaveBeenCalledWith({
|
expect(mockBase).toHaveBeenCalledWith({
|
||||||
data,
|
data,
|
||||||
onFilter: wrapper.instance().onFilter,
|
onFilter: wrapper.instance().onFilter,
|
||||||
onExternalFilter: wrapper.instance().onExternalFilter
|
onExternalFilter: wrapper.instance().onExternalFilter,
|
||||||
|
currFilters: wrapper.instance().currFilters
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -103,7 +104,6 @@ describe('FilterContext', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(shallowContext(true));
|
wrapper = shallow(shallowContext(true));
|
||||||
wrapper.render();
|
wrapper.render();
|
||||||
wrapper.instance().currFilters = { price: { filterVal: 20, filterType: FILTER_TYPE.TEXT } };
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pass original data without internal filtering', () => {
|
it('should pass original data without internal filtering', () => {
|
||||||
@@ -111,7 +111,8 @@ describe('FilterContext', () => {
|
|||||||
expect(mockBase).toHaveBeenCalledWith({
|
expect(mockBase).toHaveBeenCalledWith({
|
||||||
data,
|
data,
|
||||||
onFilter: wrapper.instance().onFilter,
|
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', () => {
|
describe('if filter.props.onFilter is defined and return data', () => {
|
||||||
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', () => {
|
|
||||||
const mockReturn = [{
|
const mockReturn = [{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'A'
|
name: 'A'
|
||||||
@@ -280,7 +255,7 @@ describe('FilterContext', () => {
|
|||||||
it('should call filter.props.onFilter correctly', () => {
|
it('should call filter.props.onFilter correctly', () => {
|
||||||
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||||
expect(onFilter).toHaveBeenCalledTimes(1);
|
expect(onFilter).toHaveBeenCalledTimes(1);
|
||||||
expect(onFilter).toHaveBeenCalledWith(filterVal);
|
expect(onFilter).toHaveBeenCalledWith(filterVal, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set data correctly', () => {
|
it('should set data correctly', () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-paginator",
|
"name": "react-bootstrap-table2-paginator",
|
||||||
"version": "2.0.7",
|
"version": "2.0.8",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.react-bootstrap-table-page-btns-ul {
|
.react-bootstrap-table-page-btns-ul {
|
||||||
float: right;
|
float: right;
|
||||||
margin-top: 0px;
|
margin-top: 0px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.react-bootstrap-table-pagination-list-hidden {
|
.react-bootstrap-table-pagination-list-hidden {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "3.1.5",
|
"version": "3.1.8",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
sortOrder={ this.props.sortOrder }
|
sortOrder={ this.props.sortOrder }
|
||||||
onSort={ this.props.onSort }
|
onSort={ this.props.onSort }
|
||||||
onFilter={ this.props.onFilter }
|
onFilter={ this.props.onFilter }
|
||||||
|
currFilters={ this.props.currFilters }
|
||||||
onExternalFilter={ this.props.onExternalFilter }
|
onExternalFilter={ this.props.onExternalFilter }
|
||||||
selectRow={ selectRow }
|
selectRow={ selectRow }
|
||||||
expandRow={ expandRow }
|
expandRow={ expandRow }
|
||||||
@@ -189,7 +190,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,
|
||||||
|
|||||||
6
packages/react-bootstrap-table2/src/const.js
vendored
6
packages/react-bootstrap-table2/src/const.js
vendored
@@ -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'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const HeaderCell = (props) => {
|
|||||||
sortOrder,
|
sortOrder,
|
||||||
isLastSorting,
|
isLastSorting,
|
||||||
onFilter,
|
onFilter,
|
||||||
|
currFilters,
|
||||||
onExternalFilter
|
onExternalFilter
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
@@ -99,7 +100,14 @@ const HeaderCell = (props) => {
|
|||||||
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||||
filterElm = filterRenderer(onCustomFilter, column);
|
filterElm = filterRenderer(onCustomFilter, column);
|
||||||
} else if (filter) {
|
} 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 ?
|
const children = headerFormatter ?
|
||||||
@@ -117,6 +125,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,
|
||||||
@@ -156,6 +170,7 @@ HeaderCell.propTypes = {
|
|||||||
sortCaret: PropTypes.func,
|
sortCaret: PropTypes.func,
|
||||||
isLastSorting: PropTypes.bool,
|
isLastSorting: PropTypes.bool,
|
||||||
onFilter: PropTypes.func,
|
onFilter: PropTypes.func,
|
||||||
|
currFilters: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func
|
onExternalFilter: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const Header = (props) => {
|
|||||||
sortField,
|
sortField,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
selectRow,
|
selectRow,
|
||||||
|
currFilters,
|
||||||
onExternalFilter,
|
onExternalFilter,
|
||||||
expandRow
|
expandRow
|
||||||
} = props;
|
} = props;
|
||||||
@@ -50,6 +51,7 @@ const Header = (props) => {
|
|||||||
onSort={ onSort }
|
onSort={ onSort }
|
||||||
sorting={ currSort }
|
sorting={ currSort }
|
||||||
onFilter={ onFilter }
|
onFilter={ onFilter }
|
||||||
|
currFilters={ currFilters }
|
||||||
onExternalFilter={ onExternalFilter }
|
onExternalFilter={ onExternalFilter }
|
||||||
sortOrder={ sortOrder }
|
sortOrder={ sortOrder }
|
||||||
isLastSorting={ isLastSorting }
|
isLastSorting={ isLastSorting }
|
||||||
@@ -89,6 +91,7 @@ Header.propTypes = {
|
|||||||
sortField: PropTypes.string,
|
sortField: PropTypes.string,
|
||||||
sortOrder: PropTypes.string,
|
sortOrder: PropTypes.string,
|
||||||
selectRow: PropTypes.object,
|
selectRow: PropTypes.object,
|
||||||
|
currFilters: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func,
|
onExternalFilter: PropTypes.func,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
expandRow: PropTypes.object
|
expandRow: PropTypes.object
|
||||||
|
|||||||
@@ -1,16 +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 _ 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 = _.contains(expandRow.expanded, key);
|
const expanded = _.contains(expandRow.expanded, key);
|
||||||
const isClosing = _.contains(expandRow.isClosing, key);
|
const isClosing = _.contains(expandRow.isClosing, key);
|
||||||
const expandable = !expandRow.nonExpandable || !_.contains(expandRow.nonExpandable, 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 }
|
||||||
@@ -18,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` }
|
||||||
@@ -25,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
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ 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.shouldRowContentUpdate(nextProps);
|
this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
18
packages/react-bootstrap-table2/src/store/type.js
vendored
Normal file
18
packages/react-bootstrap-table2/src/store/type.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import Const from '../const';
|
||||||
|
|
||||||
|
export const typeConvert = (type, value) => {
|
||||||
|
if (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;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -728,7 +728,9 @@ describe('HeaderCell', () => {
|
|||||||
Filter
|
Filter
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
wrapper = shallow(<HeaderCell column={ column } index={ index } onFilter={ onFilter } />);
|
wrapper = shallow(
|
||||||
|
<HeaderCell column={ column } index={ index } onFilter={ onFilter } currFilters={ {} } />
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user