mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 13:40:07 +00:00
Compare commits
122 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae4f503b30 | ||
|
|
0e7c145f96 | ||
|
|
a07b2da00a | ||
|
|
2068f518f6 | ||
|
|
47d6eb097a | ||
|
|
76f4795400 | ||
|
|
ee829eb924 | ||
|
|
ae34c44547 | ||
|
|
b99a277595 | ||
|
|
1d13565824 | ||
|
|
3d37a31103 | ||
|
|
f4f6649b91 | ||
|
|
8ecdbf611b | ||
|
|
4a340c714b | ||
|
|
4daa5ef4d7 | ||
|
|
acb9c9f61e | ||
|
|
6d13a86512 | ||
|
|
b5d536b8f4 | ||
|
|
e667317fbe | ||
|
|
d4ffc11f7e | ||
|
|
3c6aaacbce | ||
|
|
defcd04b52 | ||
|
|
5a44384e3c | ||
|
|
ec742a43f6 | ||
|
|
7138b68559 | ||
|
|
e6e7d6f9d2 | ||
|
|
909a6e211e | ||
|
|
83c9d69e27 | ||
|
|
aad2ad3823 | ||
|
|
9190cfc6d9 | ||
|
|
45b133579b | ||
|
|
970f7c0d15 | ||
|
|
def898f636 | ||
|
|
be916d81a3 | ||
|
|
49d1ce8812 | ||
|
|
18caf0ac8d | ||
|
|
1b9bd63370 | ||
|
|
b2121fdf24 | ||
|
|
4aaf140de5 | ||
|
|
569aa0195e | ||
|
|
cf5b24e9e8 | ||
|
|
da86b4aa1a | ||
|
|
7d28d46185 | ||
|
|
16128e77e6 | ||
|
|
ec1f96cd1f | ||
|
|
00b1558df0 | ||
|
|
4dc5e6099f | ||
|
|
d9acbace67 | ||
|
|
7c8bf00cde | ||
|
|
63df43a1e0 | ||
|
|
bb42514e56 | ||
|
|
79e3247921 | ||
|
|
c25192145f | ||
|
|
056957b0b5 | ||
|
|
c12d3faba3 | ||
|
|
963b8d669b | ||
|
|
47f6340a99 | ||
|
|
23cb0bb317 | ||
|
|
70827eecd6 | ||
|
|
43b5eeb74f | ||
|
|
eb204f6526 | ||
|
|
2b410fb8ac | ||
|
|
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 | ||
|
|
5e8bb3426a | ||
|
|
03f2ce4792 | ||
|
|
7382010822 | ||
|
|
a1a59f9419 | ||
|
|
59f184d74d | ||
|
|
643b9bca5f | ||
|
|
31724fec7f | ||
|
|
4cf6e65abc | ||
|
|
40c5ae7459 | ||
|
|
3747c36039 | ||
|
|
0d0d1a8913 | ||
|
|
db612eaa99 | ||
|
|
4d76d88e9a | ||
|
|
1cd31dc54c | ||
|
|
4ec02b294a | ||
|
|
e31b5eb691 | ||
|
|
60eb47dc9e | ||
|
|
d74ecb63b4 | ||
|
|
2c6cc915f0 | ||
|
|
a1457dfe59 | ||
|
|
036c3fdc32 | ||
|
|
55eea6f337 | ||
|
|
7c259cd1ee | ||
|
|
1e164bb3f4 | ||
|
|
8a7c1def5b | ||
|
|
77b8ed53bf | ||
|
|
6bc54ef3ec | ||
|
|
6168bd7532 | ||
|
|
36fa9b8630 | ||
|
|
737922a5a4 | ||
|
|
0f37fae23d | ||
|
|
ce7e05d7f9 | ||
|
|
067006eb72 | ||
|
|
8fa10e3b6f |
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.
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,12 @@
|
|||||||
* [rowClasses](#rowClasses)
|
* [rowClasses](#rowClasses)
|
||||||
* [rowEvents](#rowEvents)
|
* [rowEvents](#rowEvents)
|
||||||
* [hiddenRows](#hiddenRows)
|
* [hiddenRows](#hiddenRows)
|
||||||
|
* [sort](#sort)
|
||||||
* [defaultSorted](#defaultSorted)
|
* [defaultSorted](#defaultSorted)
|
||||||
* [defaultSortDirection](#defaultSortDirection)
|
* [defaultSortDirection](#defaultSortDirection)
|
||||||
* [pagination](#pagination)
|
* [pagination](#pagination)
|
||||||
* [filter](#filter)
|
* [filter](#filter)
|
||||||
|
* [filterPosition](filterPosition)
|
||||||
* [onTableChange](#onTableChange)
|
* [onTableChange](#onTableChange)
|
||||||
* [onDataSizeChange](#onDataSizeChange)
|
* [onDataSizeChange](#onDataSizeChange)
|
||||||
|
|
||||||
@@ -98,7 +100,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>
|
||||||
@@ -191,6 +200,27 @@ const hiddenRows = [1, 4];
|
|||||||
<BootstrapTable data={ data } columns={ columns } hiddenRows={ hiddenRows } />
|
<BootstrapTable data={ data } columns={ columns } hiddenRows={ hiddenRows } />
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='sort'>sort - [Object]</a>
|
||||||
|
Two cases you probably need to configure `sort` prop:
|
||||||
|
|
||||||
|
#### Manage sorting state
|
||||||
|
You can give `dataField` and `order` to specify the sorting state in table, For example
|
||||||
|
|
||||||
|
```js
|
||||||
|
<BootstrapTable sort={ { dataField: 'price', order: 'asc' } }>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### One-time sorting configuration
|
||||||
|
In earily version, we only can configure [`sortCaret`](./columns.md#sortCaret) and [`sortFunc` ](./columns.md#sortFunc) per column. But they are same in most of cases.
|
||||||
|
So here we give you a chance to just setup these prop in one time.
|
||||||
|
|
||||||
|
```js
|
||||||
|
<BootstrapTable sort={ {
|
||||||
|
sortCaret: ...
|
||||||
|
sortFunc: ...
|
||||||
|
} }>
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='defaultSorted'>defaultSorted - [Array]</a>
|
### <a name='defaultSorted'>defaultSorted - [Array]</a>
|
||||||
`defaultSorted` accept an object array which allow you to define the default sort columns when first render.
|
`defaultSorted` accept an object array which allow you to define the default sort columns when first render.
|
||||||
|
|
||||||
@@ -201,6 +231,8 @@ const defaultSorted = [{
|
|||||||
}];
|
}];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note**: Only the first column is sorted currently, see #1083.
|
||||||
|
|
||||||
### <a name='defaultSortDirection'>defaultSortDirection - [String]</a>
|
### <a name='defaultSortDirection'>defaultSortDirection - [String]</a>
|
||||||
Default sort direction when user click on header column at first time, available value is `asc` and `desc`. Default is `desc`.
|
Default sort direction when user click on header column at first time, available value is `asc` and `desc`. Default is `desc`.
|
||||||
|
|
||||||
@@ -320,6 +352,9 @@ Following is a shape of `newState`
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='filterPosition'>filterPosition - [String]</a>
|
||||||
|
Available value is `inline`, `top` and `bottom`, default is `inline`. This prop decide where `react-bootstrap-table` render column filter.
|
||||||
|
|
||||||
### <a name='onDataSizeChange'>onDataSizeChange - [Function]</a>
|
### <a name='onDataSizeChange'>onDataSizeChange - [Function]</a>
|
||||||
This callback function will be called only when data size change by search/filter etc. This function have one argument which is an object contains below props:
|
This callback function will be called only when data size change by search/filter etc. This function have one argument which is an object contains below props:
|
||||||
|
|
||||||
@@ -334,4 +369,4 @@ handleDataChange = ({ dataSize }) => {
|
|||||||
onDataSizeChange={ handleDataChange }
|
onDataSizeChange={ handleDataChange }
|
||||||
....
|
....
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ Available properties in a column object:
|
|||||||
* [hidden](#hidden)
|
* [hidden](#hidden)
|
||||||
* [formatter](#formatter)
|
* [formatter](#formatter)
|
||||||
* [formatExtraData](#formatExtraData)
|
* [formatExtraData](#formatExtraData)
|
||||||
|
* [type](#type)
|
||||||
* [sort](#sort)
|
* [sort](#sort)
|
||||||
|
* [sortValue](#sortValue)
|
||||||
* [sortFunc](#sortFunc)
|
* [sortFunc](#sortFunc)
|
||||||
* [sortCaret](#sortCaret)
|
* [sortCaret](#sortCaret)
|
||||||
* [onSort](#onSort)
|
* [onSort](#onSort)
|
||||||
@@ -48,6 +50,7 @@ Available properties in a column object:
|
|||||||
* [editorRenderer](#editorRenderer)
|
* [editorRenderer](#editorRenderer)
|
||||||
* [filter](#filter)
|
* [filter](#filter)
|
||||||
* [filterValue](#filterValue)
|
* [filterValue](#filterValue)
|
||||||
|
* [searchable](#searchable)
|
||||||
* [csvType](#csvType)
|
* [csvType](#csvType)
|
||||||
* [csvFormatter](#csvFormatter)
|
* [csvFormatter](#csvFormatter)
|
||||||
* [csvText](#csvText)
|
* [csvText](#csvText)
|
||||||
@@ -132,11 +135,49 @@ 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.
|
||||||
|
|
||||||
|
## <a name='sortValue'>column.sortValue - [Function]</a>
|
||||||
|
`column.sortValue` only work when `column.sort` enabled. This prop allow you to replace the value when table sorting.
|
||||||
|
|
||||||
|
For example, consider following data:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
|
||||||
|
const data = [{id: 1, type: 2}, {id: 2, type: 1}, {id: 3, type:0}];
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Job ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type'
|
||||||
|
sort: true,
|
||||||
|
formatter: (cell, row) => types[cell]
|
||||||
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
|
In above case, when user try to sort Job Type column which will sort the original value: 0, 1, 2 but we display the type name via [`column.formatter`](#formatter), which will lead confuse because we are sorting by type value instead of type name. So `sortValue` is a way for you to decide what kind of value should be adopted when sorting on a specify column:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Job ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type'
|
||||||
|
sort: true,
|
||||||
|
formatter: (cell, row) => types[cell],
|
||||||
|
sortValue: (cell, row) => types[cell] // we use type name to sort.
|
||||||
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
## <a name='sortFunc'>column.sortFunc - [Function]</a>
|
## <a name='sortFunc'>column.sortFunc - [Function]</a>
|
||||||
`column.sortFunc` only work when `column.sort` is enable. `sortFunc` allow you to define your sorting algorithm. This callback function accept six arguments:
|
`column.sortFunc` only work when `column.sort` enabled. `sortFunc` allow you to define your sorting algorithm. This callback function accept six arguments:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -415,7 +456,7 @@ If the events is not listed above, the callback function will only pass the `eve
|
|||||||
{
|
{
|
||||||
// omit...
|
// omit...
|
||||||
headerEvents: {
|
headerEvents: {
|
||||||
onClick: e => { ... }
|
onClick: (e, column, columnIndex) => { ... }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -625,7 +666,7 @@ It's also available to custom via a callback function:
|
|||||||
{
|
{
|
||||||
// omit...
|
// omit...
|
||||||
footerEvents: {
|
footerEvents: {
|
||||||
onClick: e => { ... }
|
onClick: (e, column, columnIndex) => { ... }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -912,6 +953,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>
|
## <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.
|
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,8 @@
|
|||||||
* [expandColumnPosition](#expandColumnPosition)
|
* [expandColumnPosition](#expandColumnPosition)
|
||||||
* [expandColumnRenderer](#expandColumnRenderer)
|
* [expandColumnRenderer](#expandColumnRenderer)
|
||||||
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
|
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
|
||||||
|
* [className](#className)
|
||||||
|
* [parentClassName](#parentClassName)
|
||||||
|
|
||||||
### <a name="renderer">expandRow.renderer - [Function]</a>
|
### <a name="renderer">expandRow.renderer - [Function]</a>
|
||||||
|
|
||||||
@@ -25,12 +27,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 +168,45 @@ const expandRow = {
|
|||||||
expandColumnPosition: 'right'
|
expandColumnPosition: 'right'
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <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:
|
||||||
|
|
||||||
|
```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';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
# Row selection
|
# Row selection
|
||||||
`react-bootstrap-table2` supports the row selection feature. By passing prop `selectRow` to enable row selection. When you enable this feature, `react-bootstrap-table2` will append a new selection column at first.
|
`react-bootstrap-table2` supports the row selection feature. By passing prop `selectRow` to enable row selection. When you enable this feature, `react-bootstrap-table2` will prepend a new selection column.
|
||||||
|
|
||||||
## Required
|
## Required
|
||||||
* [mode (**required**)](#mode)
|
* [mode (**required**)](#mode)
|
||||||
@@ -11,15 +11,20 @@
|
|||||||
* [classes)](#classes)
|
* [classes)](#classes)
|
||||||
* [bgColor](#bgColor)
|
* [bgColor](#bgColor)
|
||||||
* [nonSelectable)](#nonSelectable)
|
* [nonSelectable)](#nonSelectable)
|
||||||
|
* [nonSelectableStyle](#nonSelectableStyle)
|
||||||
|
* [nonSelectableClasses](#nonSelectableClasses)
|
||||||
* [clickToSelect)](#clickToSelect)
|
* [clickToSelect)](#clickToSelect)
|
||||||
* [clickToExpand)](#clickToExpand)
|
* [clickToExpand)](#clickToExpand)
|
||||||
* [clickToEdit](#clickToEdit)
|
* [clickToEdit](#clickToEdit)
|
||||||
* [onSelect](#onSelect)
|
* [onSelect](#onSelect)
|
||||||
* [onSelectAll](#onSelectAll)
|
* [onSelectAll](#onSelectAll)
|
||||||
|
* [selectColumnPosition](#selectColumnPosition)
|
||||||
* [hideSelectColumn](#hideSelectColumn)
|
* [hideSelectColumn](#hideSelectColumn)
|
||||||
* [hideSelectAll](#hideSelectAll)
|
* [hideSelectAll](#hideSelectAll)
|
||||||
* [selectionRenderer](#selectionRenderer)
|
* [selectionRenderer](#selectionRenderer)
|
||||||
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
||||||
|
* [headerColumnStyle](#headerColumnStyle)
|
||||||
|
* [selectColumnStyle](#selectColumnStyle)
|
||||||
|
|
||||||
### <a name="mode">selectRow.mode - [String]</a>
|
### <a name="mode">selectRow.mode - [String]</a>
|
||||||
|
|
||||||
@@ -136,6 +141,54 @@ const selectRow = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='nonSelectableStyle'>selectRow.nonSelectableStyle - [Object | Function]</a>
|
||||||
|
This prop allow you to customize the non selectable rows. `selectRow.nonSelectableStyle` accepts an style object
|
||||||
|
and a callback function for more flexible customization.
|
||||||
|
|
||||||
|
### Style Object
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableStyle: (row, rowIndex) => { return ...; }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### <a name='nonSelectableClasses'>selectRow.nonSelectableClasses - [String | Function]</a>
|
||||||
|
This prop allow you to set a custom class for the non selectable rows, or use a callback function for more
|
||||||
|
flexible customization
|
||||||
|
|
||||||
|
### String
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableClasses: 'my-class'
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableClasses: (row, rowIndex) => { return ...; }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
|
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
|
||||||
Allow user to select row by clicking on the row.
|
Allow user to select row by clicking on the row.
|
||||||
|
|
||||||
@@ -146,7 +199,7 @@ const selectRow = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
|
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
|
||||||
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
|
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
|
||||||
|
|
||||||
### <a name='clickToExpand'>selectRow.clickToExpand - [Bool]</a>
|
### <a name='clickToExpand'>selectRow.clickToExpand - [Bool]</a>
|
||||||
@@ -198,6 +251,67 @@ const selectRow = {
|
|||||||
|
|
||||||
> By default, `react-bootstrap-table2` will help you to handle the click event, it's not necessary to handle again by developer.
|
> By default, `react-bootstrap-table2` will help you to handle the click event, it's not necessary to handle again by developer.
|
||||||
|
|
||||||
|
|
||||||
|
### <a name='headerColumnStyle'>selectRow.headerColumnStyle - [Object | Function]</a>
|
||||||
|
A way to custome the selection header cell. `headerColumnStyle` not only accept a simple style object but also a callback function for more flexible customization:
|
||||||
|
|
||||||
|
### Style Object
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
headerColumnStyle: { backgroundColor: 'blue' }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
headerColumnStyle: (status) => (
|
||||||
|
// status available value is checked, indeterminate and unchecked
|
||||||
|
return { backgroundColor: 'blue' };
|
||||||
|
)
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### <a name='selectColumnStyle'>selectRow.selectColumnStyle - [Object | Function]</a>
|
||||||
|
A way to custome the selection cell. `selectColumnStyle` not only accept a simple style object but also a callback function for more flexible customization:
|
||||||
|
|
||||||
|
### Style Object
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
selectColumnStyle: { backgroundColor: 'blue' }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
If a callback function present, you can get below information to custom the selection cell:
|
||||||
|
|
||||||
|
* `checked`: Whether current row is seleccted or not
|
||||||
|
* `disabled`: Whether current row is disabled or not
|
||||||
|
* `rowIndex`: Current row index
|
||||||
|
* `rowKey`: Current row key
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
selectColumnStyle: ({
|
||||||
|
checked,
|
||||||
|
disabled,
|
||||||
|
rowIndex,
|
||||||
|
rowKey
|
||||||
|
}) => (
|
||||||
|
// ....
|
||||||
|
return { backgroundColor: 'blue' };
|
||||||
|
)
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
||||||
This callback function will be called when a row is select/unselect and pass following three arguments:
|
This callback function will be called when a row is select/unselect and pass following three arguments:
|
||||||
`row`, `isSelect`, `rowIndex` and `e`.
|
`row`, `isSelect`, `rowIndex` and `e`.
|
||||||
@@ -243,12 +357,22 @@ const selectRow = {
|
|||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
onSelectAll: (isSelect, rows, e) => {
|
onSelectAll: (isSelect, rows, e) => {
|
||||||
if (isSelect && SOME_CONDITION) {
|
if (isSelect && SOME_CONDITION) {
|
||||||
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
|
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='selectColumnPosition'>selectRow.selectColumnPosition - [String]</a>
|
||||||
|
Default is `left`. You can give this as `right` for rendering selection column in the right side.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
selectColumnPosition: 'right'
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
|
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
|
||||||
Default is `false`, if you don't want to have a selection column, give this prop as `true`
|
Default is `false`, if you don't want to have a selection column, give this prop as `true`
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
"webpack-dev-server": "2.7.1"
|
"webpack-dev-server": "2.7.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"classnames": "2.2.5",
|
"classnames": "^2.2.5",
|
||||||
"prop-types": "15.5.10",
|
"prop-types": "15.5.10",
|
||||||
"react": "16.4.0",
|
"react": "16.4.0",
|
||||||
"react-dom": "16.4.0",
|
"react-dom": "16.4.0",
|
||||||
|
|||||||
@@ -89,7 +89,10 @@ const columns = [
|
|||||||
In the following, we go though all the predefined editors:
|
In the following, we go though all the predefined editors:
|
||||||
|
|
||||||
### Dropdown Editor
|
### Dropdown Editor
|
||||||
Dropdown editor give a select menu to choose a data from a list, the `editor.options` is required property for dropdown editor.
|
Dropdown editor give a select menu to choose a data from a list. When use dropdown editor, either `editor.options` or `editor.getOptions` should be required prop.
|
||||||
|
|
||||||
|
#### editor.options
|
||||||
|
This is most simple case for assign the dropdown options data directly.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { Type } from 'react-bootstrap-table2-editor';
|
import { Type } from 'react-bootstrap-table2-editor';
|
||||||
@@ -119,6 +122,46 @@ const columns = [
|
|||||||
}];
|
}];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### editor.getOptions
|
||||||
|
It is much flexible which accept a function and you can assign the dropdown options dynamically.
|
||||||
|
|
||||||
|
There are two case for `getOptions`:
|
||||||
|
|
||||||
|
* *Synchronous*: Just return the options array in `getOptions` callback function
|
||||||
|
* *Asynchronous*: Call `setOptions` function argument when you get the options from remote.
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Synchronous
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
..., {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type',
|
||||||
|
editor: {
|
||||||
|
type: Type.SELECT,
|
||||||
|
getOptions: (setOptions, { row, column }) => [.....]
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
// Asynchronous
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
..., {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type',
|
||||||
|
editor: {
|
||||||
|
type: Type.SELECT,
|
||||||
|
getOptions: (setOptions, { row, column }) => {
|
||||||
|
setTimeout(() => setOptions([...]), 1500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
[here](https://react-bootstrap-table.github.io/react-bootstrap-table2/storybook/index.html?selectedKind=Cell%20Editing&selectedStory=Dropdown%20Editor%20with%20Dynamic%20Options) is an online example.
|
||||||
|
|
||||||
### Date Editor
|
### Date Editor
|
||||||
Date editor is use `<input type="date">`, the configuration is very simple:
|
Date editor is use `<input type="date">`, the configuration is very simple:
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-editor",
|
"name": "react-bootstrap-table2-editor",
|
||||||
"version": "1.2.3",
|
"version": "1.4.0",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
/* eslint disable-next-line: 0 */
|
||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
|
/* eslint react/no-unused-prop-types: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT } from './const';
|
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT } from './const';
|
||||||
@@ -43,7 +46,7 @@ export default (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.cellEdit && isRemoteCellEdit()) {
|
if (nextProps.cellEdit && isRemoteCellEdit()) {
|
||||||
if (nextProps.cellEdit.options.errorMessage) {
|
if (nextProps.cellEdit.options.errorMessage) {
|
||||||
this.setState(() => ({
|
this.setState(() => ({
|
||||||
@@ -56,12 +59,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 +73,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 +82,7 @@ export default (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.doUpdate(row, column, newValue);
|
this.doUpdate(row, column, newValueWithType);
|
||||||
}
|
}
|
||||||
|
|
||||||
doUpdate(row, column, newValue) {
|
doUpdate(row, column, newValue) {
|
||||||
|
|||||||
@@ -4,6 +4,21 @@ import cs from 'classnames';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
class DropDownEditor extends Component {
|
class DropDownEditor extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
let options = props.options;
|
||||||
|
if (props.getOptions) {
|
||||||
|
options = props.getOptions(
|
||||||
|
this.setOptions.bind(this),
|
||||||
|
{
|
||||||
|
row: props.row,
|
||||||
|
column: props.column
|
||||||
|
}
|
||||||
|
) || [];
|
||||||
|
}
|
||||||
|
this.state = { options };
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { defaultValue, didMount } = this.props;
|
const { defaultValue, didMount } = this.props;
|
||||||
this.select.value = defaultValue;
|
this.select.value = defaultValue;
|
||||||
@@ -11,12 +26,16 @@ class DropDownEditor extends Component {
|
|||||||
if (didMount) didMount();
|
if (didMount) didMount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOptions(options) {
|
||||||
|
this.setState({ options });
|
||||||
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue() {
|
||||||
return this.select.value;
|
return this.select.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { defaultValue, didMount, className, options, ...rest } = this.props;
|
const { defaultValue, didMount, getOptions, className, ...rest } = this.props;
|
||||||
const editorClass = cs('form-control editor edit-select', className);
|
const editorClass = cs('form-control editor edit-select', className);
|
||||||
|
|
||||||
const attr = {
|
const attr = {
|
||||||
@@ -31,7 +50,7 @@ class DropDownEditor extends Component {
|
|||||||
defaultValue={ defaultValue }
|
defaultValue={ defaultValue }
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
options.map(({ label, value }) => (
|
this.state.options.map(({ label, value }) => (
|
||||||
<option key={ value } value={ value }>{ label }</option>
|
<option key={ value } value={ value }>{ label }</option>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -41,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
|
||||||
@@ -52,13 +73,16 @@ DropDownEditor.propTypes = {
|
|||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
value: PropTypes.any
|
value: PropTypes.any
|
||||||
}))
|
}))
|
||||||
]).isRequired,
|
]),
|
||||||
didMount: PropTypes.func
|
didMount: PropTypes.func,
|
||||||
|
getOptions: PropTypes.func
|
||||||
};
|
};
|
||||||
DropDownEditor.defaultProps = {
|
DropDownEditor.defaultProps = {
|
||||||
className: '',
|
className: '',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
style: {},
|
style: {},
|
||||||
didMount: undefined
|
options: [],
|
||||||
|
didMount: undefined,
|
||||||
|
getOptions: undefined
|
||||||
};
|
};
|
||||||
export default DropDownEditor;
|
export default DropDownEditor;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
/* eslint class-methods-use-this: 0 */
|
/* eslint class-methods-use-this: 0 */
|
||||||
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
|
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import cs from 'classnames';
|
import cs from 'classnames';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
@@ -51,7 +52,11 @@ export default (_, onStartEdit) =>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps({ message }) {
|
componentWillUnmount() {
|
||||||
|
this.clearTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps({ message }) {
|
||||||
if (_.isDefined(message)) {
|
if (_.isDefined(message)) {
|
||||||
this.createTimer();
|
this.createTimer();
|
||||||
this.setState(() => ({
|
this.setState(() => ({
|
||||||
@@ -60,10 +65,6 @@ export default (_, onStartEdit) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.clearTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
clearTimer() {
|
clearTimer() {
|
||||||
if (this.indicatorTimer) {
|
if (this.indicatorTimer) {
|
||||||
clearTimeout(this.indicatorTimer);
|
clearTimeout(this.indicatorTimer);
|
||||||
@@ -201,7 +202,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) {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ describe('CellEditContext', () => {
|
|||||||
wrapper = shallow(shallowContext());
|
wrapper = shallow(shallowContext());
|
||||||
wrapper.setState(initialState);
|
wrapper.setState(initialState);
|
||||||
wrapper.render();
|
wrapper.render();
|
||||||
wrapper.instance().componentWillReceiveProps({});
|
wrapper.instance().UNSAFE_componentWillReceiveProps({});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not set state.message', () => {
|
it('should not set state.message', () => {
|
||||||
@@ -138,7 +138,7 @@ describe('CellEditContext', () => {
|
|||||||
wrapper = shallow(shallowContext());
|
wrapper = shallow(shallowContext());
|
||||||
wrapper.setState(initialState);
|
wrapper.setState(initialState);
|
||||||
wrapper.render();
|
wrapper.render();
|
||||||
wrapper.instance().componentWillReceiveProps({
|
wrapper.instance().UNSAFE_componentWillReceiveProps({
|
||||||
cellEdit: cellEditFactory(defaultCellEdit)
|
cellEdit: cellEditFactory(defaultCellEdit)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -164,7 +164,7 @@ describe('CellEditContext', () => {
|
|||||||
wrapper = shallow(shallowContext(defaultCellEdit, true));
|
wrapper = shallow(shallowContext(defaultCellEdit, true));
|
||||||
wrapper.setState(initialState);
|
wrapper.setState(initialState);
|
||||||
wrapper.render();
|
wrapper.render();
|
||||||
wrapper.instance().componentWillReceiveProps({
|
wrapper.instance().UNSAFE_componentWillReceiveProps({
|
||||||
cellEdit: cellEditFactory({
|
cellEdit: cellEditFactory({
|
||||||
...defaultCellEdit,
|
...defaultCellEdit,
|
||||||
errorMessage: message
|
errorMessage: message
|
||||||
@@ -190,7 +190,7 @@ describe('CellEditContext', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(shallowContext(defaultCellEdit, true));
|
wrapper = shallow(shallowContext(defaultCellEdit, true));
|
||||||
wrapper.setState(initialState);
|
wrapper.setState(initialState);
|
||||||
wrapper.instance().componentWillReceiveProps({
|
wrapper.instance().UNSAFE_componentWillReceiveProps({
|
||||||
cellEdit: cellEditFactory({ ...defaultCellEdit })
|
cellEdit: cellEditFactory({ ...defaultCellEdit })
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|||||||
@@ -45,8 +45,12 @@ class ExposedFunctionTable extends React.Component {
|
|||||||
console.log(this.node.table.props.data);
|
console.log(this.node.table.props.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleGetCurrentData = () => {
|
||||||
|
console.log(this.node.table.props.data);
|
||||||
|
}
|
||||||
|
|
||||||
handleGetSelectedData = () => {
|
handleGetSelectedData = () => {
|
||||||
console.log(this.node.selectionContext.state.selected);
|
console.log(this.node.selectionContext.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGetExpandedData = () => {
|
handleGetExpandedData = () => {
|
||||||
@@ -117,7 +121,7 @@ export default class ExposedFunctionTable extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleGetSelectedData = () => {
|
handleGetSelectedData = () => {
|
||||||
console.log(this.node.selectionContext.state.selected);
|
console.log(this.node.selectionContext.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGetExpandedData = () => {
|
handleGetExpandedData = () => {
|
||||||
|
|||||||
49
packages/react-bootstrap-table2-example/examples/bootstrap4/caption-table.js
vendored
Normal file
49
packages/react-bootstrap-table2-example/examples/bootstrap4/caption-table.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const CaptionElement = () => <h3 style={{ borderRadius: '0.25em', textAlign: 'center', color: 'purple', border: '1px solid purple', padding: '0.5em' }}>Component as Header</h3>;
|
||||||
|
|
||||||
|
<BootstrapTable bootstrap4 keyField="id" data={ products } caption="Plain text header" columns={ columns } />
|
||||||
|
|
||||||
|
<BootstrapTable bootstrap4 keyField="id" data={ products } caption={<CaptionElement />} columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Caption = () => <h3 style={ { borderRadius: '0.25em', textAlign: 'center', color: 'purple', border: '1px solid purple', padding: '0.5em' } }>Component as Header</h3>;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable bootstrap4 keyField="id" data={ products } caption="Plain text header" columns={ columns } />
|
||||||
|
<BootstrapTable bootstrap4 keyField="id" data={ products } caption={ <Caption /> } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
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>
|
||||||
|
);
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
/* eslint no-console: 0 */
|
||||||
|
/* eslint react/prefer-stateless-function: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { jobsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const jobs = jobsGenerator().map(j => ({
|
||||||
|
...j,
|
||||||
|
type2: j.type
|
||||||
|
}));
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Job ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Job Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'owner',
|
||||||
|
text: 'Job Owner'
|
||||||
|
}, {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type1',
|
||||||
|
editor: {
|
||||||
|
type: Type.SELECT,
|
||||||
|
getOptions: (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',
|
||||||
|
text: 'Job Type2',
|
||||||
|
editor: {
|
||||||
|
type: Type.SELECT,
|
||||||
|
getOptions: (setOptions) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
setOptions([{
|
||||||
|
value: 'A',
|
||||||
|
label: 'A'
|
||||||
|
}, {
|
||||||
|
value: 'B',
|
||||||
|
label: 'B'
|
||||||
|
}, {
|
||||||
|
value: 'C',
|
||||||
|
label: 'C'
|
||||||
|
}, {
|
||||||
|
value: 'D',
|
||||||
|
label: 'D'
|
||||||
|
}, {
|
||||||
|
value: 'E',
|
||||||
|
label: 'E'
|
||||||
|
}]);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Job ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Job Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'owner',
|
||||||
|
text: 'Job Owner'
|
||||||
|
}, {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type1',
|
||||||
|
editor: {
|
||||||
|
type: Type.SELECT,
|
||||||
|
getOptions: (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',
|
||||||
|
text: 'Job Type2',
|
||||||
|
editor: {
|
||||||
|
type: Type.SELECT,
|
||||||
|
getOptions: (setOptions) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
setOptions([{
|
||||||
|
value: 'A',
|
||||||
|
label: 'A'
|
||||||
|
}, {
|
||||||
|
value: 'B',
|
||||||
|
label: 'B'
|
||||||
|
}, {
|
||||||
|
value: 'C',
|
||||||
|
label: 'C'
|
||||||
|
}, {
|
||||||
|
value: 'D',
|
||||||
|
label: 'D'
|
||||||
|
}, {
|
||||||
|
value: 'E',
|
||||||
|
label: 'E'
|
||||||
|
}]);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ jobs }
|
||||||
|
columns={ columns }
|
||||||
|
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<h3>Dropdown Editor with Dynamic Options</h3>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ jobs }
|
||||||
|
columns={ columns }
|
||||||
|
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -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 }
|
||||||
|
|||||||
114
packages/react-bootstrap-table2-example/examples/column-filter/filter-position.js
vendored
Normal file
114
packages/react-bootstrap-table2-example/examples/column-filter/filter-position.js
vendored
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(8);
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode1 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
filterPosition="top"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const sourceCode2 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
filterPosition="bottom"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const expandRow = {
|
||||||
|
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>
|
||||||
|
),
|
||||||
|
showExpandColumn: true,
|
||||||
|
expandColumnPosition: 'right'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
filterPosition="top"
|
||||||
|
expandRow={ expandRow }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode1 }</Code>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
filterPosition="bottom"
|
||||||
|
expandRow={ expandRow }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode2 }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
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>
|
||||||
|
);
|
||||||
@@ -8,14 +8,17 @@ const products = productsGenerator(8);
|
|||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
text: 'Product ID'
|
text: 'Product ID',
|
||||||
|
footer: 'hello'
|
||||||
}, {
|
}, {
|
||||||
dataField: 'name',
|
dataField: 'name',
|
||||||
text: 'Product Name',
|
text: 'Product Name',
|
||||||
|
footer: 'hello',
|
||||||
filter: textFilter()
|
filter: textFilter()
|
||||||
}, {
|
}, {
|
||||||
dataField: 'price',
|
dataField: 'price',
|
||||||
text: 'Product Price',
|
text: 'Product Price',
|
||||||
|
footer: 'hello',
|
||||||
filter: textFilter()
|
filter: textFilter()
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -39,6 +42,11 @@ const columns = [{
|
|||||||
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true
|
||||||
|
};
|
||||||
|
|
||||||
export default () => (
|
export default () => (
|
||||||
<div>
|
<div>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
@@ -46,6 +54,8 @@ export default () => (
|
|||||||
data={ products }
|
data={ products }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
filter={ filterFactory() }
|
filter={ filterFactory() }
|
||||||
|
filterPosition="bottom"
|
||||||
|
selectRow={ selectRow }
|
||||||
/>
|
/>
|
||||||
<Code>{ sourceCode }</Code>
|
<Code>{ sourceCode }</Code>
|
||||||
</div>
|
</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>
|
||||||
|
);
|
||||||
188
packages/react-bootstrap-table2-example/examples/columns/row-expand-with-formatted-dummy-column.js
vendored
Normal file
188
packages/react-bootstrap-table2-example/examples/columns/row-expand-with-formatted-dummy-column.js
vendored
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
/* eslint no-param-reassign: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
class DummyColumnWithRowExpand extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
hoverIdx: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
expandRow = {
|
||||||
|
renderer: () => (
|
||||||
|
<div style={ { width: '100%', height: '20px' } }>Content</div>
|
||||||
|
),
|
||||||
|
showExpandColumn: true,
|
||||||
|
expandByColumnOnly: true
|
||||||
|
};
|
||||||
|
|
||||||
|
actionFormater = (cell, row, rowIndex, { hoverIdx }) => {
|
||||||
|
if ((hoverIdx !== null || hoverIdx !== undefined) && hoverIdx === rowIndex) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={ { width: '20px', height: '20px', backgroundColor: 'orange' } }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={ { width: '20px', height: '20px' } }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
rowEvents = {
|
||||||
|
onMouseEnter: (e, row, rowIndex) => {
|
||||||
|
this.setState({ hoverIdx: rowIndex });
|
||||||
|
},
|
||||||
|
onMouseLeave: () => {
|
||||||
|
this.setState({ hoverIdx: null });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rowStyle = (row, rowIndex) => {
|
||||||
|
row.index = rowIndex;
|
||||||
|
const style = {};
|
||||||
|
if (rowIndex % 2 === 0) {
|
||||||
|
style.backgroundColor = 'transparent';
|
||||||
|
} else {
|
||||||
|
style.backgroundColor = 'rgba(54, 163, 173, .10)';
|
||||||
|
}
|
||||||
|
style.borderTop = 'none';
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}, {
|
||||||
|
text: '',
|
||||||
|
isDummyField: true,
|
||||||
|
formatter: this.actionFormater,
|
||||||
|
formatExtraData: { hoverIdx: this.state.hoverIdx },
|
||||||
|
headerStyle: { width: '50px' },
|
||||||
|
style: { height: '30px' }
|
||||||
|
}];
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
noDataIndication="There is no data"
|
||||||
|
classes="table"
|
||||||
|
rowStyle={ this.rowStyle }
|
||||||
|
rowEvents={ this.rowEvents }
|
||||||
|
expandRow={ this.expandRow }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class DummyColumnWithRowExpand extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
hoverIdx: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
expandRow = {
|
||||||
|
renderer: () => (
|
||||||
|
<div style={ { width: '100%', height: '20px' } }>Content</div>
|
||||||
|
),
|
||||||
|
showExpandColumn: true,
|
||||||
|
expandByColumnOnly: true
|
||||||
|
};
|
||||||
|
|
||||||
|
actionFormater = (cell, row, rowIndex, { hoverIdx }) => {
|
||||||
|
if ((hoverIdx !== null || hoverIdx !== undefined) && hoverIdx === rowIndex) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={ { width: '20px', height: '20px', backgroundColor: 'orange' } }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={ { width: '20px', height: '20px' } }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
rowEvents = {
|
||||||
|
onMouseEnter: (e, row, rowIndex) => {
|
||||||
|
this.setState({ hoverIdx: rowIndex });
|
||||||
|
},
|
||||||
|
onMouseLeave: () => {
|
||||||
|
this.setState({ hoverIdx: null });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rowStyle = (row, rowIndex) => {
|
||||||
|
row.index = rowIndex;
|
||||||
|
const style = {};
|
||||||
|
if (rowIndex % 2 === 0) {
|
||||||
|
style.backgroundColor = 'transparent';
|
||||||
|
} else {
|
||||||
|
style.backgroundColor = 'rgba(54, 163, 173, .10)';
|
||||||
|
}
|
||||||
|
style.borderTop = 'none';
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}, {
|
||||||
|
isDummyField: true,
|
||||||
|
text: '',
|
||||||
|
formatter: this.actionFormater,
|
||||||
|
formatExtraData: { hoverIdx: this.state.hoverIdx },
|
||||||
|
headerStyle: { width: '50px' },
|
||||||
|
style: { height: '30px' }
|
||||||
|
}];
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
rowStyle={ this.rowStyle }
|
||||||
|
rowEvents={ this.rowEvents }
|
||||||
|
expandRow={ this.expandRow }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,13 @@ const columns = [{
|
|||||||
keyField="id"
|
keyField="id"
|
||||||
data={ products }
|
data={ products }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
exportCSV
|
exportCSV={ {
|
||||||
|
fileName: 'custom.csv',
|
||||||
|
separator: '|',
|
||||||
|
ignoreHeader: true,
|
||||||
|
noAutoBOM: false,
|
||||||
|
blobType: 'text/csv;charset=ansi'
|
||||||
|
} }
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
props => (
|
props => (
|
||||||
@@ -64,7 +70,8 @@ export default () => (
|
|||||||
fileName: 'custom.csv',
|
fileName: 'custom.csv',
|
||||||
separator: '|',
|
separator: '|',
|
||||||
ignoreHeader: true,
|
ignoreHeader: true,
|
||||||
noAutoBOM: false
|
noAutoBOM: false,
|
||||||
|
blobType: 'text/csv;charset=ansi'
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,11 +36,12 @@ const columns = [{
|
|||||||
|
|
||||||
const MyExportCSV = (props) => {
|
const MyExportCSV = (props) => {
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
props.onExport();
|
// passing my custom data
|
||||||
|
props.onExport(products.filter(r => r.id > 2));
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<button className="btn btn-success" onClick={ handleClick }>Export to CSV</button>
|
<button className="btn btn-success" onClick={ handleClick }>Only export Product ID bigger than 2</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
92
packages/react-bootstrap-table2-example/examples/csv/export-footer.js
vendored
Normal file
92
packages/react-bootstrap-table2-example/examples/csv/export-footer.js
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { CSVExport } from 'react-bootstrap-table2-toolkit';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const { ExportCSVButton } = CSVExport;
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: '',
|
||||||
|
footerFormatter: column => column.text
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: columnData => columnData.reduce((acc, item) => acc + item, 0)
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { CSVExport } from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const { ExportCSVButton } = CSVExport;
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
exportCSV={ {
|
||||||
|
fileName: 'custom.csv',
|
||||||
|
separator: '|',
|
||||||
|
ignoreHeader: true,
|
||||||
|
noAutoBOM: false,
|
||||||
|
blobType: 'text/csv;charset=ansi'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable { ...props.baseProps } />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
exportCSV={ {
|
||||||
|
ignoreFooter: false
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable { ...props.baseProps } />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -12,7 +12,7 @@ const columns = [{
|
|||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
text: 'Product ID',
|
text: 'Product ID',
|
||||||
footerEvents: {
|
footerEvents: {
|
||||||
onClick: () => alert('Click on Product ID footer column')
|
onClick: (e, column, columnIndex) => alert(`Click on Product ID header column, columnIndex: ${columnIndex}`)
|
||||||
},
|
},
|
||||||
footer: 'Footer 1'
|
footer: 'Footer 1'
|
||||||
}, {
|
}, {
|
||||||
@@ -32,7 +32,7 @@ const columns = [{
|
|||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
text: 'Product ID',
|
text: 'Product ID',
|
||||||
footerEvents: {
|
footerEvents: {
|
||||||
onClick: () => alert('Click on Product ID footer column')
|
onClick: (e, column, columnIndex) => alert('Click on Product ID footer column')
|
||||||
},
|
},
|
||||||
footer: 'Footer 1'
|
footer: 'Footer 1'
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const columns = [{
|
|||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
text: 'Product ID',
|
text: 'Product ID',
|
||||||
headerEvents: {
|
headerEvents: {
|
||||||
onClick: () => alert('Click on Product ID header column')
|
onClick: (e, column, columnIndex) => alert(`Click on Product ID header column, columnIndex: ${columnIndex}`)
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
dataField: 'name',
|
dataField: 'name',
|
||||||
@@ -29,7 +29,7 @@ const columns = [{
|
|||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
text: 'Product ID',
|
text: 'Product ID',
|
||||||
headerEvents: {
|
headerEvents: {
|
||||||
onClick: () => alert('Click on Product ID header column')
|
onClick: (e, column, columnIndex) => alert('Click on Product ID header column')
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
dataField: 'name',
|
dataField: 'name',
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const options = {
|
|||||||
// hidePageListOnlyOnePage: true, // Hide the pagination list when only one page
|
// hidePageListOnlyOnePage: true, // Hide the pagination list when only one page
|
||||||
firstPageText: 'First',
|
firstPageText: 'First',
|
||||||
prePageText: 'Back',
|
prePageText: 'Back',
|
||||||
nextPageText: 'Next',
|
nextPageText: <span>Next</span>,
|
||||||
lastPageText: 'Last',
|
lastPageText: 'Last',
|
||||||
nextPageTitle: 'First page',
|
nextPageTitle: 'First page',
|
||||||
prePageTitle: 'Pre page',
|
prePageTitle: 'Pre page',
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ const columns = [{
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
const expandRow = {
|
const expandRow = {
|
||||||
|
onlyOneExpanding: true,
|
||||||
renderer: row => (
|
renderer: row => (
|
||||||
<div>
|
<div>
|
||||||
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
|
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
|
||||||
|
|||||||
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>
|
||||||
|
);
|
||||||
@@ -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>
|
||||||
|
);
|
||||||
111
packages/react-bootstrap-table2-example/examples/row-selection/header-style.js
vendored
Normal file
111
packages/react-bootstrap-table2-example/examples/row-selection/header-style.js
vendored
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(2);
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow1 = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: {
|
||||||
|
backgroundColor: 'blue'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode1 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = ...
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: {
|
||||||
|
backgroundColor: 'blue'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const selectRow2 = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: (status) => {
|
||||||
|
if (status === 'checked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'yellow'
|
||||||
|
};
|
||||||
|
} else if (status === 'indeterminate') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'pink'
|
||||||
|
};
|
||||||
|
} else if (status === 'unchecked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'grey'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode2 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = ...
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: (status) => {
|
||||||
|
if (status === 'checked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'yellow'
|
||||||
|
};
|
||||||
|
} else if (status === 'indeterminate') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'pink'
|
||||||
|
};
|
||||||
|
} else if (status === 'unchecked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'grey'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow1 } />
|
||||||
|
<Code>{ sourceCode1 }</Code>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow2 } />
|
||||||
|
<Code>{ sourceCode2 }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-class.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-class.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableClasses: 'row-index-bigger-than-2101'
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableClasses: 'row-index-bigger-than-2101'
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-style.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-style.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
110
packages/react-bootstrap-table2-example/examples/row-selection/select-column-style.js
vendored
Normal file
110
packages/react-bootstrap-table2-example/examples/row-selection/select-column-style.js
vendored
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(2);
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow1 = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
selectColumnStyle: {
|
||||||
|
backgroundColor: 'grey'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode1 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = ...
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
selectColumnStyle: {
|
||||||
|
backgroundColor: 'grey'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const selectRow2 = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
selectColumnStyle: ({
|
||||||
|
checked,
|
||||||
|
disabled,
|
||||||
|
rowIndex,
|
||||||
|
rowKey
|
||||||
|
}) => {
|
||||||
|
if (checked) {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'yellow'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
backgroundColor: 'pink'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode2 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = ...
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
selectColumnStyle: ({
|
||||||
|
checked,
|
||||||
|
disabled,
|
||||||
|
rowIndex,
|
||||||
|
rowKey
|
||||||
|
}) => {
|
||||||
|
if (checked) {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'yellow'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
backgroundColor: 'pink'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow1 } />
|
||||||
|
<Code>{ sourceCode1 }</Code>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow2 } />
|
||||||
|
<Code>{ sourceCode2 }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
59
packages/react-bootstrap-table2-example/examples/row-selection/selection-column-position.js
vendored
Normal file
59
packages/react-bootstrap-table2-example/examples/row-selection/selection-column-position.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
selectColumnPosition: 'right'
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
selectColumnPosition: 'right'
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
116
packages/react-bootstrap-table2-example/examples/search/custom-match-function.js
vendored
Normal file
116
packages/react-bootstrap-table2-example/examples/search/custom-match-function.js
vendored
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
/* eslint no-unused-vars: 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'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
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'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
// Implement startWith instead of contain
|
||||||
|
function customMatchFunc({
|
||||||
|
searchText,
|
||||||
|
value,
|
||||||
|
column,
|
||||||
|
row
|
||||||
|
}) {
|
||||||
|
if (typeof value !== 'undefined') {
|
||||||
|
return value.startsWith(searchText);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search={ { customMatchFunc } }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<h3>Input something at below input field:</h3>
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Implement startWith instead of contain
|
||||||
|
function customMatchFunc({
|
||||||
|
searchText,
|
||||||
|
value,
|
||||||
|
column,
|
||||||
|
row
|
||||||
|
}) {
|
||||||
|
if (typeof value !== 'undefined') {
|
||||||
|
return `${value}`.toLowerCase().startsWith(searchText.toLowerCase());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<h1>Custom a search match function by startWith instead of contain</h1>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search={ { onColumnMatch: customMatchFunc } }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<h3>Input something at below input field:</h3>
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</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>
|
||||||
|
);
|
||||||
78
packages/react-bootstrap-table2-example/examples/sort/custom-sort-value.js
vendored
Normal file
78
packages/react-bootstrap-table2-example/examples/sort/custom-sort-value.js
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { jobsGenerator1 } from 'utils/common';
|
||||||
|
|
||||||
|
const jobs = jobsGenerator1(8);
|
||||||
|
|
||||||
|
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Job ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Job Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'owner',
|
||||||
|
text: 'Job Owner'
|
||||||
|
}, {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type',
|
||||||
|
sort: true,
|
||||||
|
formatter: (cell, row) => types[cell],
|
||||||
|
sortValue: (cell, row) => types[cell]
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Job ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Job Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'owner',
|
||||||
|
text: 'Job Owner'
|
||||||
|
}, {
|
||||||
|
dataField: 'type',
|
||||||
|
text: 'Job Type',
|
||||||
|
sort: true,
|
||||||
|
formatter: (cell, row) => types[cell],
|
||||||
|
sortValue: (cell, row) => types[cell]
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class Test extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { data: jobs };
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClick = () => {
|
||||||
|
this.setState(() => {
|
||||||
|
const newProducts = jobsGenerator1(21);
|
||||||
|
return {
|
||||||
|
data: newProducts
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleClick }>Change Data</button>
|
||||||
|
<BootstrapTable keyField="id" data={ this.state.data } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
98
packages/react-bootstrap-table2-example/examples/sort/one-time-sort-configuration.js
vendored
Normal file
98
packages/react-bootstrap-table2-example/examples/sort/one-time-sort-configuration.js
vendored
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
class OnetimeSortConfiguration extends React.Component {
|
||||||
|
sortFunc = (a, b, order, dataField) => {
|
||||||
|
if (order === 'asc') {
|
||||||
|
return b - a;
|
||||||
|
}
|
||||||
|
return a - b; // desc
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const sortOption = {
|
||||||
|
// No need to configure sortFunc per column
|
||||||
|
sortFunc: this.sortFunc,
|
||||||
|
// No need to configure sortCaret per column
|
||||||
|
sortCaret: (order, column) => {
|
||||||
|
if (!order) return (<span> Desc/Asc</span>);
|
||||||
|
else if (order === 'asc') return (<span> Desc/<font color="red">Asc</font></span>);
|
||||||
|
else if (order === 'desc') return (<span> <font color="red">Desc</font>/Asc</span>);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleClick }>Change Data</button>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } sort={ sortOption } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class OnetimeSortConfiguration extends React.Component {
|
||||||
|
sortFunc = (a, b, order, dataField) => {
|
||||||
|
if (order === 'asc') {
|
||||||
|
return b - a;
|
||||||
|
}
|
||||||
|
return a - b; // desc
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const sortOption = {
|
||||||
|
sortFunc: this.sortFunc,
|
||||||
|
sortCaret: (order, column) => {
|
||||||
|
if (!order) return (<span> Desc/Asc</span>);
|
||||||
|
else if (order === 'asc') return (<span> Desc/<font color="red">Asc</font></span>);
|
||||||
|
else if (order === 'desc') return (<span> <font color="red">Desc</font>/Asc</span>);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3>Reverse Sorting Table</h3>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } sort={ sortOption } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
118
packages/react-bootstrap-table2-example/examples/sort/sort-management.js
vendored
Normal file
118
packages/react-bootstrap-table2-example/examples/sort/sort-management.js
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/* eslint no-console: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
class SortManagement extends React.Component {
|
||||||
|
state = {
|
||||||
|
field: null,
|
||||||
|
order: null
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSort = (field, order) => {
|
||||||
|
this.setState({
|
||||||
|
field,
|
||||||
|
order
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSortById = () => {
|
||||||
|
this.setState({
|
||||||
|
field: 'id',
|
||||||
|
order: 'desc'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
sort: true,
|
||||||
|
onSort: this.handleSort
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true,
|
||||||
|
onSort: this.handleSort
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-danger" onClick={ this.handleSortById }>Sort By ID</button>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
sort={ {
|
||||||
|
dataField: this.state.field,
|
||||||
|
order: this.state.order
|
||||||
|
} }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class SortManagement extends React.Component {
|
||||||
|
state = {
|
||||||
|
field: null,
|
||||||
|
order: null
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSort = (field, order) => {
|
||||||
|
this.setState({
|
||||||
|
field,
|
||||||
|
order
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSortById = () => {
|
||||||
|
this.setState({
|
||||||
|
field: 'id',
|
||||||
|
order: 'desc'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
sort: true,
|
||||||
|
onSort: this.handleSort
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true,
|
||||||
|
onSort: this.handleSort
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-danger" onClick={ this.handleSortById }>Sort By ID</button>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
sort={ {
|
||||||
|
dataField: this.state.field,
|
||||||
|
order: this.state.order
|
||||||
|
} }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.24",
|
"version": "1.0.36",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ export const withOnSale = rows => rows.map((row) => {
|
|||||||
return row;
|
return row;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const withRandomPrice = rows => rows.map((row) => {
|
||||||
|
row.price = Math.floor((Math.random() * 10) + 2000);
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
|
||||||
export const productsQualityGenerator = (quantity = 5, factor = 0) =>
|
export const productsQualityGenerator = (quantity = 5, factor = 0) =>
|
||||||
Array.from({ length: quantity }, (value, index) => ({
|
Array.from({ length: quantity }, (value, index) => ({
|
||||||
id: index + factor,
|
id: index + factor,
|
||||||
@@ -69,8 +74,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()))
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import TabIndexCellTable from 'examples/basic/tabindex-column';
|
|||||||
|
|
||||||
// bootstrap 4
|
// bootstrap 4
|
||||||
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
||||||
|
import Bootstrap4CaptionTable from 'examples/bootstrap4/caption-table';
|
||||||
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
|
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
|
||||||
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
|
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
|
||||||
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
|
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
|
||||||
@@ -35,6 +36,7 @@ import ColumnEventTable from 'examples/columns/column-event-table';
|
|||||||
import ColumnHiddenTable from 'examples/columns/column-hidden-table';
|
import ColumnHiddenTable from 'examples/columns/column-hidden-table';
|
||||||
import ColumnAttrsTable from 'examples/columns/column-attrs-table';
|
import ColumnAttrsTable from 'examples/columns/column-attrs-table';
|
||||||
import DummyColumnTable from 'examples/columns/dummy-column-table';
|
import DummyColumnTable from 'examples/columns/dummy-column-table';
|
||||||
|
import RowExpandWithFormattedDummyColumn from 'examples/columns/row-expand-with-formatted-dummy-column.js';
|
||||||
|
|
||||||
// work on header columns
|
// work on header columns
|
||||||
import HeaderColumnFormatTable from 'examples/header-columns/column-format-table';
|
import HeaderColumnFormatTable from 'examples/header-columns/column-format-table';
|
||||||
@@ -67,6 +69,7 @@ import TextFilterCaseSensitive from 'examples/column-filter/text-filter-caseSens
|
|||||||
import CustomTextFilter from 'examples/column-filter/custom-text-filter';
|
import CustomTextFilter from 'examples/column-filter/custom-text-filter';
|
||||||
import CustomFilterValue from 'examples/column-filter/custom-filter-value';
|
import CustomFilterValue from 'examples/column-filter/custom-filter-value';
|
||||||
import SelectFilter from 'examples/column-filter/select-filter';
|
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 SelectFilterWithDefaultValue from 'examples/column-filter/select-filter-default-value';
|
||||||
import SelectFilterComparator from 'examples/column-filter/select-filter-like-comparator';
|
import SelectFilterComparator from 'examples/column-filter/select-filter-like-comparator';
|
||||||
import SelectFilterWithPreservedOptionsOrder from 'examples/column-filter/select-filter-preserve-option-order';
|
import SelectFilterWithPreservedOptionsOrder from 'examples/column-filter/select-filter-preserve-option-order';
|
||||||
@@ -90,6 +93,7 @@ import AdvanceCustomFilter from 'examples/column-filter/advance-custom-filter';
|
|||||||
import ClearAllFilters from 'examples/column-filter/clear-all-filters';
|
import ClearAllFilters from 'examples/column-filter/clear-all-filters';
|
||||||
import FilterHooks from 'examples/column-filter/filter-hooks';
|
import FilterHooks from 'examples/column-filter/filter-hooks';
|
||||||
import CustomFilterLogic from 'examples/column-filter/custom-filter-logic';
|
import CustomFilterLogic from 'examples/column-filter/custom-filter-logic';
|
||||||
|
import FilterPosition from 'examples/column-filter/filter-position';
|
||||||
|
|
||||||
// work on rows
|
// work on rows
|
||||||
import RowStyleTable from 'examples/rows/row-style';
|
import RowStyleTable from 'examples/rows/row-style';
|
||||||
@@ -102,6 +106,9 @@ import EnableSortTable from 'examples/sort/enable-sort-table';
|
|||||||
import DefaultSortTable from 'examples/sort/default-sort-table';
|
import DefaultSortTable from 'examples/sort/default-sort-table';
|
||||||
import DefaultSortDirectionTable from 'examples/sort/default-sort-direction';
|
import DefaultSortDirectionTable from 'examples/sort/default-sort-direction';
|
||||||
import SortEvents from 'examples/sort/sort-events';
|
import SortEvents from 'examples/sort/sort-events';
|
||||||
|
import SortManagement from 'examples/sort/sort-management';
|
||||||
|
import OneTimeSortConfiguration from 'examples/sort/one-time-sort-configuration';
|
||||||
|
import CustomSortValue from 'examples/sort/custom-sort-value';
|
||||||
import CustomSortTable from 'examples/sort/custom-sort-table';
|
import CustomSortTable from 'examples/sort/custom-sort-table';
|
||||||
import CustomSortCaretTable from 'examples/sort/custom-sort-caret';
|
import CustomSortCaretTable from 'examples/sort/custom-sort-caret';
|
||||||
import HeaderSortingClassesTable from 'examples/sort/header-sorting-classes';
|
import HeaderSortingClassesTable from 'examples/sort/header-sorting-classes';
|
||||||
@@ -125,10 +132,12 @@ import EditorStyleTable from 'examples/cell-edit/editor-style-table';
|
|||||||
import EditorClassTable from 'examples/cell-edit/editor-class-table';
|
import EditorClassTable from 'examples/cell-edit/editor-class-table';
|
||||||
import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table';
|
import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table';
|
||||||
import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table';
|
import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table';
|
||||||
|
import DropdownEditorWithDynamicOptionsTable from 'examples/cell-edit/dropdown-editor-with-dynamic-options-table';
|
||||||
import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table';
|
import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table';
|
||||||
import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table';
|
import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table';
|
||||||
import DateEditorTable from 'examples/cell-edit/date-editor-table';
|
import DateEditorTable from 'examples/cell-edit/date-editor-table';
|
||||||
import CustomEditorTable from 'examples/cell-edit/custom-editor-table';
|
import CustomEditorTable from 'examples/cell-edit/custom-editor-table';
|
||||||
|
import CellEditorWithDataType from 'examples/cell-edit/cell-edit-with-data-type';
|
||||||
|
|
||||||
// work on row selection
|
// work on row selection
|
||||||
import SingleSelectionTable from 'examples/row-selection/single-selection';
|
import SingleSelectionTable from 'examples/row-selection/single-selection';
|
||||||
@@ -142,12 +151,17 @@ import SelectionWithExpansionTable from 'examples/row-selection/selection-with-e
|
|||||||
import SelectionNoDataTable from 'examples/row-selection/selection-no-data';
|
import SelectionNoDataTable from 'examples/row-selection/selection-no-data';
|
||||||
import SelectionStyleTable from 'examples/row-selection/selection-style';
|
import SelectionStyleTable from 'examples/row-selection/selection-style';
|
||||||
import SelectionClassTable from 'examples/row-selection/selection-class';
|
import SelectionClassTable from 'examples/row-selection/selection-class';
|
||||||
|
import HeaderStyleTable from 'examples/row-selection/header-style';
|
||||||
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
||||||
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
||||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
||||||
|
import NonSelectableRowsStyleTable from 'examples/row-selection/non-selectable-rows-style';
|
||||||
|
import NonSelectableRowsClassTable from 'examples/row-selection/non-selectable-rows-class';
|
||||||
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||||
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
||||||
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
||||||
|
import SelectionColumnStyleTable from 'examples/row-selection/select-column-style';
|
||||||
|
import SelectionColumnPositionTable from 'examples/row-selection/selection-column-position';
|
||||||
|
|
||||||
// work on row expand
|
// work on row expand
|
||||||
import BasicRowExpand from 'examples/row-expand';
|
import BasicRowExpand from 'examples/row-expand';
|
||||||
@@ -159,6 +173,8 @@ 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';
|
||||||
|
import ExpandingRowClassName from 'examples/row-expand/expanding-row-classname';
|
||||||
|
|
||||||
// pagination
|
// pagination
|
||||||
import PaginationTable from 'examples/pagination';
|
import PaginationTable from 'examples/pagination';
|
||||||
@@ -185,6 +201,8 @@ import DefaultCustomSearch from 'examples/search/default-custom-search';
|
|||||||
import FullyCustomSearch from 'examples/search/fully-custom-search';
|
import FullyCustomSearch from 'examples/search/fully-custom-search';
|
||||||
import SearchFormattedData from 'examples/search/search-formatted';
|
import SearchFormattedData from 'examples/search/search-formatted';
|
||||||
import CustomSearchValue from 'examples/search/custom-search-value';
|
import CustomSearchValue from 'examples/search/custom-search-value';
|
||||||
|
import SearchableColumn from 'examples/search/searchable-column';
|
||||||
|
import CustomMatchFunction from 'examples/search/custom-match-function';
|
||||||
|
|
||||||
// CSV
|
// CSV
|
||||||
import ExportCSV from 'examples/csv';
|
import ExportCSV from 'examples/csv';
|
||||||
@@ -197,12 +215,14 @@ import CSVColumnType from 'examples/csv/csv-column-type';
|
|||||||
import CustomCSVButton from 'examples/csv/custom-csv-button';
|
import CustomCSVButton from 'examples/csv/custom-csv-button';
|
||||||
import ExportCustomData from 'examples/csv/export-custom-data';
|
import ExportCustomData from 'examples/csv/export-custom-data';
|
||||||
import CustomCSV from 'examples/csv/custom-csv';
|
import CustomCSV from 'examples/csv/custom-csv';
|
||||||
|
import ExportTableFooter from 'examples/csv/export-footer';
|
||||||
|
|
||||||
// Column toggle
|
// Column toggle
|
||||||
import BasicColumnToggle from 'examples/column-toggle';
|
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';
|
||||||
@@ -252,6 +272,7 @@ storiesOf('Basic Table', module)
|
|||||||
storiesOf('Bootstrap 4', module)
|
storiesOf('Bootstrap 4', module)
|
||||||
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
||||||
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
|
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
|
||||||
|
.add('Table Caption bootstrap 4', () => <Bootstrap4CaptionTable />)
|
||||||
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
|
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
|
||||||
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
|
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
|
||||||
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
|
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
|
||||||
@@ -269,7 +290,8 @@ storiesOf('Work on Columns', module)
|
|||||||
.add('Customize Column Class', () => <ColumnClassTable />)
|
.add('Customize Column Class', () => <ColumnClassTable />)
|
||||||
.add('Customize Column Style', () => <ColumnStyleTable />)
|
.add('Customize Column Style', () => <ColumnStyleTable />)
|
||||||
.add('Customize Column HTML attribute', () => <ColumnAttrsTable />)
|
.add('Customize Column HTML attribute', () => <ColumnAttrsTable />)
|
||||||
.add('Dummy Column', () => <DummyColumnTable />);
|
.add('Dummy Column', () => <DummyColumnTable />)
|
||||||
|
.add('Row Expand with Dummy Column Formatter', () => <RowExpandWithFormattedDummyColumn />);
|
||||||
|
|
||||||
storiesOf('Work on Header Columns', module)
|
storiesOf('Work on Header Columns', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -291,6 +313,7 @@ storiesOf('Column Filter', module)
|
|||||||
.add('Text Filter with Case Sensitive', () => <TextFilterCaseSensitive />)
|
.add('Text Filter with Case Sensitive', () => <TextFilterCaseSensitive />)
|
||||||
// add another filter type example right here.
|
// add another filter type example right here.
|
||||||
.add('Select Filter', () => <SelectFilter />)
|
.add('Select Filter', () => <SelectFilter />)
|
||||||
|
.add('Configure Select Filter Options', () => <ConfigureSelectFilterOptions />)
|
||||||
.add('Select Filter with Default Value', () => <SelectFilterWithDefaultValue />)
|
.add('Select Filter with Default Value', () => <SelectFilterWithDefaultValue />)
|
||||||
.add('Select Filter with Comparator', () => <SelectFilterComparator />)
|
.add('Select Filter with Comparator', () => <SelectFilterComparator />)
|
||||||
.add('MultiSelect Filter', () => <MultiSelectFilter />)
|
.add('MultiSelect Filter', () => <MultiSelectFilter />)
|
||||||
@@ -299,6 +322,7 @@ storiesOf('Column Filter', module)
|
|||||||
.add('Number Filter with Default Value', () => <NumberFilterWithDefaultValue />)
|
.add('Number Filter with Default Value', () => <NumberFilterWithDefaultValue />)
|
||||||
.add('Date Filter', () => <DateFilter />)
|
.add('Date Filter', () => <DateFilter />)
|
||||||
.add('Date Filter with Default Value', () => <DateFilterWithDefaultValue />)
|
.add('Date Filter with Default Value', () => <DateFilterWithDefaultValue />)
|
||||||
|
.add('Filter Position', () => <FilterPosition />)
|
||||||
.add('Custom Text Filter', () => <CustomTextFilter />)
|
.add('Custom Text Filter', () => <CustomTextFilter />)
|
||||||
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
||||||
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
||||||
@@ -343,6 +367,9 @@ storiesOf('Sort Table', module)
|
|||||||
.add('Default Sort Table', () => <DefaultSortTable />)
|
.add('Default Sort Table', () => <DefaultSortTable />)
|
||||||
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
||||||
.add('Sort Events', () => <SortEvents />)
|
.add('Sort Events', () => <SortEvents />)
|
||||||
|
.add('Sort Management', () => <SortManagement />)
|
||||||
|
.add('One-time Sort Configuation', () => <OneTimeSortConfiguration />)
|
||||||
|
.add('Custom Sort Value', () => <CustomSortValue />)
|
||||||
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
||||||
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
|
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
|
||||||
.add('Custom Classes on Sorting Header Column', () => <HeaderSortingClassesTable />)
|
.add('Custom Classes on Sorting Header Column', () => <HeaderSortingClassesTable />)
|
||||||
@@ -367,10 +394,12 @@ storiesOf('Cell Editing', module)
|
|||||||
.add('Custom Editor Style', () => <EditorStyleTable />)
|
.add('Custom Editor Style', () => <EditorStyleTable />)
|
||||||
.add('DoubleClick to Edit with Selection', () => <DBClickEditWithSelection />)
|
.add('DoubleClick to Edit with Selection', () => <DBClickEditWithSelection />)
|
||||||
.add('Dropdown Editor', () => <DropdownEditorTable />)
|
.add('Dropdown Editor', () => <DropdownEditorTable />)
|
||||||
|
.add('Dropdown Editor with Dynamic Options', () => <DropdownEditorWithDynamicOptionsTable />)
|
||||||
.add('Textarea Editor', () => <TextareaEditorTable />)
|
.add('Textarea Editor', () => <TextareaEditorTable />)
|
||||||
.add('Checkbox Editor', () => <CheckboxEditorTable />)
|
.add('Checkbox Editor', () => <CheckboxEditorTable />)
|
||||||
.add('Date Editor', () => <DateEditorTable />)
|
.add('Date Editor', () => <DateEditorTable />)
|
||||||
.add('Custom Editor', () => <CustomEditorTable />);
|
.add('Custom Editor', () => <CustomEditorTable />)
|
||||||
|
.add('Cell Editor with Data Type', () => <CellEditorWithDataType />);
|
||||||
|
|
||||||
storiesOf('Row Selection', module)
|
storiesOf('Row Selection', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -385,12 +414,17 @@ storiesOf('Row Selection', module)
|
|||||||
.add('Selection without Data', () => <SelectionNoDataTable />)
|
.add('Selection without Data', () => <SelectionNoDataTable />)
|
||||||
.add('Selection Style', () => <SelectionStyleTable />)
|
.add('Selection Style', () => <SelectionStyleTable />)
|
||||||
.add('Selection Class', () => <SelectionClassTable />)
|
.add('Selection Class', () => <SelectionClassTable />)
|
||||||
|
.add('Custom Selection Column Header Style', () => <HeaderStyleTable />)
|
||||||
.add('Hide Select All', () => <HideSelectAllTable />)
|
.add('Hide Select All', () => <HideSelectAllTable />)
|
||||||
.add('Custom Selection', () => <CustomSelectionTable />)
|
.add('Custom Selection', () => <CustomSelectionTable />)
|
||||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||||
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
||||||
|
.add('Not Selectabled Rows Style', () => <NonSelectableRowsStyleTable />)
|
||||||
|
.add('Not Selectabled Rows Class', () => <NonSelectableRowsClassTable />)
|
||||||
.add('Selection Hooks', () => <SelectionHooks />)
|
.add('Selection Hooks', () => <SelectionHooks />)
|
||||||
.add('Hide Selection Column', () => <HideSelectionColumnTable />);
|
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
|
||||||
|
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
|
||||||
|
.add('Selection Column Position', () => <SelectionColumnPositionTable />);
|
||||||
|
|
||||||
storiesOf('Row Expand', module)
|
storiesOf('Row Expand', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -402,7 +436,9 @@ 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 />)
|
||||||
|
.add('Custom Expanding Row ClassName', () => <ExpandingRowClassName />);
|
||||||
|
|
||||||
storiesOf('Pagination', module)
|
storiesOf('Pagination', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -428,16 +464,19 @@ storiesOf('Table Search', module)
|
|||||||
.add('Clear Search Button', () => <ClearSearchButton />)
|
.add('Clear Search Button', () => <ClearSearchButton />)
|
||||||
.add('Default Search Table', () => <DefaultSearch />)
|
.add('Default Search Table', () => <DefaultSearch />)
|
||||||
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
||||||
|
.add('Searchable Column', () => <SearchableColumn />)
|
||||||
.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 />)
|
||||||
|
.add('Custom match function', () => <CustomMatchFunction />);
|
||||||
|
|
||||||
storiesOf('Column Toggle', module)
|
storiesOf('Column Toggle', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
.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())
|
||||||
@@ -450,7 +489,8 @@ storiesOf('Export CSV', module)
|
|||||||
.add('CSV Column Type', () => <CSVColumnType />)
|
.add('CSV Column Type', () => <CSVColumnType />)
|
||||||
.add('Custom CSV Button', () => <CustomCSVButton />)
|
.add('Custom CSV Button', () => <CustomCSVButton />)
|
||||||
.add('Export Custom Data', () => <ExportCustomData />)
|
.add('Export Custom Data', () => <ExportCustomData />)
|
||||||
.add('Custom CSV', () => <CustomCSV />);
|
.add('Custom CSV', () => <CustomCSV />)
|
||||||
|
.add('Export Table Footer', () => <ExportTableFooter />);
|
||||||
|
|
||||||
storiesOf('EmptyTableOverlay', module)
|
storiesOf('EmptyTableOverlay', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.expanding-foo, .parent-expand-foo {
|
||||||
|
background-color: coral;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expanding-bar, .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";
|
||||||
@@ -115,7 +115,9 @@ const qualityFilter = selectFilter({
|
|||||||
// omit...
|
// 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
|
```js
|
||||||
const selectOptions = [
|
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.
|
The benifit is `react-bootstrap-table2` will render the select options by the order of array.
|
||||||
|
|
||||||
@@ -310,3 +330,29 @@ Following properties is valid in `FILTER_TYPES`:
|
|||||||
* NUMBER
|
* NUMBER
|
||||||
* DATE
|
* DATE
|
||||||
* MULTISELECT
|
* MULTISELECT
|
||||||
|
|
||||||
|
### Position
|
||||||
|
Default filter is rendered inside the table column header, but you can choose to render them as a row by `filterPosition`:
|
||||||
|
|
||||||
|
#### Render in the top of table body
|
||||||
|
|
||||||
|
```js
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
filterPosition="top"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Render in the bottom of table body
|
||||||
|
```js
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
filterPosition="bottom"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-filter",
|
"name": "react-bootstrap-table2-filter",
|
||||||
"version": "1.1.9",
|
"version": "1.3.0",
|
||||||
"description": "it's a column filter addon for react-bootstrap-table2",
|
"description": "it's a column filter addon for react-bootstrap-table2",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -18,8 +18,18 @@ function optionsEquals(currOpts, prevOpts) {
|
|||||||
return Object.keys(currOpts).length === Object.keys(prevOpts).length;
|
return Object.keys(currOpts).length === Object.keys(prevOpts).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSelections = container =>
|
const getSelections = (container) => {
|
||||||
Array.from(container.selectedOptions).map(item => item.value);
|
if (container.selectedOptions) {
|
||||||
|
return Array.from(container.selectedOptions).map(item => item.value);
|
||||||
|
}
|
||||||
|
const selections = [];
|
||||||
|
const totalLen = container.options.length;
|
||||||
|
for (let i = 0; i < totalLen; i += 1) {
|
||||||
|
const option = container.options.item(i);
|
||||||
|
if (option.selected) selections.push(option.value);
|
||||||
|
}
|
||||||
|
return selections;
|
||||||
|
};
|
||||||
|
|
||||||
class MultiSelectFilter extends Component {
|
class MultiSelectFilter extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -55,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;
|
||||||
@@ -96,6 +114,7 @@ class MultiSelectFilter extends Component {
|
|||||||
const {
|
const {
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
|
filterState,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
onFilter,
|
onFilter,
|
||||||
column,
|
column,
|
||||||
@@ -125,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>
|
||||||
@@ -138,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,
|
||||||
@@ -150,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,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
/* eslint react/no-unused-prop-types: 0 */
|
/* eslint react/no-unused-prop-types: 0 */
|
||||||
|
/* eslint class-methods-use-this: 0 */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { LIKE, EQ } from '../comparison';
|
import { LIKE, EQ } from '../comparison';
|
||||||
@@ -44,7 +45,8 @@ 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;
|
this.options = this.getOptions(props);
|
||||||
|
const isSelected = getOptionValue(this.options, this.getDefaultValue()) !== undefined;
|
||||||
this.state = { isSelected };
|
this.state = { isSelected };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,36 +71,36 @@ class SelectFilter extends Component {
|
|||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
let needFilter = false;
|
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;
|
needFilter = true;
|
||||||
} else if (!optionsEquals(this.props.options, prevProps.options)) {
|
} else if (!optionsEquals(nextOptions, this.options)) {
|
||||||
|
this.options = nextOptions;
|
||||||
needFilter = true;
|
needFilter = true;
|
||||||
}
|
}
|
||||||
if (needFilter) {
|
if (needFilter) {
|
||||||
const value = this.selectInput.value;
|
const value = this.selectInput.value;
|
||||||
if (value) {
|
if (value) {
|
||||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
onFilter(column, FILTER_TYPE.SELECT)(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getOptions() {
|
getOptions(props) {
|
||||||
const optionTags = [];
|
return typeof props.options === 'function' ? props.options(props.column) : props.options;
|
||||||
const { options, placeholder, column, withoutEmptyOption } = this.props;
|
}
|
||||||
if (!withoutEmptyOption) {
|
|
||||||
optionTags.push((
|
getDefaultValue() {
|
||||||
<option key="-1" value="">{ placeholder || `Select ${column.text}...` }</option>
|
const { filterState, defaultValue } = this.props;
|
||||||
));
|
if (filterState && typeof filterState.filterVal !== 'undefined') {
|
||||||
|
return filterState.filterVal;
|
||||||
}
|
}
|
||||||
if (Array.isArray(options)) {
|
return defaultValue;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanFiltered() {
|
cleanFiltered() {
|
||||||
@@ -120,6 +122,26 @@ class SelectFilter extends Component {
|
|||||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
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() {
|
render() {
|
||||||
const {
|
const {
|
||||||
style,
|
style,
|
||||||
@@ -132,6 +154,7 @@ class SelectFilter extends Component {
|
|||||||
withoutEmptyOption,
|
withoutEmptyOption,
|
||||||
caseSensitive,
|
caseSensitive,
|
||||||
getFilter,
|
getFilter,
|
||||||
|
filterState,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -152,9 +175,9 @@ 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.renderOptions() }
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
@@ -164,6 +187,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 +201,7 @@ SelectFilter.propTypes = {
|
|||||||
|
|
||||||
SelectFilter.defaultProps = {
|
SelectFilter.defaultProps = {
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
|
filterState: {},
|
||||||
className: '',
|
className: '',
|
||||||
withoutEmptyOption: false,
|
withoutEmptyOption: false,
|
||||||
comparator: EQ,
|
comparator: EQ,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { PropTypes } from 'prop-types';
|
import { PropTypes } from 'prop-types';
|
||||||
|
|
||||||
@@ -13,8 +14,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()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,16 +42,16 @@ class TextFilter extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillUnmount() {
|
||||||
|
this.cleanTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.defaultValue !== this.props.defaultValue) {
|
if (nextProps.defaultValue !== this.props.defaultValue) {
|
||||||
this.applyFilter(nextProps.defaultValue);
|
this.applyFilter(nextProps.defaultValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.cleanTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
filter(e) {
|
filter(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.cleanTimer();
|
this.cleanTimer();
|
||||||
@@ -89,6 +96,7 @@ class TextFilter extends Component {
|
|||||||
caseSensitive,
|
caseSensitive,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
getFilter,
|
getFilter,
|
||||||
|
filterState,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -119,6 +127,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 +140,7 @@ TextFilter.propTypes = {
|
|||||||
|
|
||||||
TextFilter.defaultProps = {
|
TextFilter.defaultProps = {
|
||||||
delay: FILTER_DELAY,
|
delay: FILTER_DELAY,
|
||||||
|
filterState: {},
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
caseSensitive: false
|
caseSensitive: false
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
@@ -37,15 +38,6 @@ export default (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
// let nextData = nextProps.data;
|
|
||||||
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
|
|
||||||
this.doFilter(nextProps, undefined, this.isEmitDataChange);
|
|
||||||
} else {
|
|
||||||
this.data = nextProps.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onFilter(column, filterType, initialize = false) {
|
onFilter(column, filterType, initialize = false) {
|
||||||
return (filterVal) => {
|
return (filterVal) => {
|
||||||
// watch out here if migration to context API, #334
|
// watch out here if migration to context API, #334
|
||||||
@@ -76,12 +68,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 +82,18 @@ export default (
|
|||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
doFilter(props, customResult, ignoreEmitDataChange = false) {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
let result = customResult;
|
// let nextData = nextProps.data;
|
||||||
|
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
|
||||||
|
this.doFilter(nextProps, this.isEmitDataChange);
|
||||||
|
} else {
|
||||||
|
this.data = nextProps.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doFilter(props, ignoreEmitDataChange = false) {
|
||||||
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 +109,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 }
|
||||||
|
|||||||
@@ -234,16 +234,28 @@ export const filters = (data, columns, _) => (currFilters) => {
|
|||||||
let result = data;
|
let result = data;
|
||||||
let filterFn;
|
let filterFn;
|
||||||
Object.keys(currFilters).forEach((dataField) => {
|
Object.keys(currFilters).forEach((dataField) => {
|
||||||
|
let currentResult;
|
||||||
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) {
|
||||||
|
currentResult = customFilter(filterObj.filterVal, result);
|
||||||
|
}
|
||||||
|
if (typeof currentResult === 'undefined') {
|
||||||
|
result = filterFn(result, dataField, filterObj, filterValue);
|
||||||
|
} else {
|
||||||
|
result = currentResult;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
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();
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ describe('Text Filter', () => {
|
|||||||
<TextFilter onFilter={ onFilter } column={ column } />
|
<TextFilter onFilter={ onFilter } column={ column } />
|
||||||
);
|
);
|
||||||
instance = wrapper.instance();
|
instance = wrapper.instance();
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should setting state correctly when props.defaultValue is changed', () => {
|
it('should setting state correctly when props.defaultValue is changed', () => {
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ export default options => loading =>
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
const { wrapper } = this.overlay;
|
const { wrapper } = this.overlay;
|
||||||
const masker = wrapper.firstChild;
|
const masker = wrapper.current.firstChild;
|
||||||
const headerDOM = wrapper.parentElement.querySelector('thead');
|
const headerDOM = wrapper.current.parentElement.querySelector('thead');
|
||||||
const bodyDOM = wrapper.parentElement.querySelector('tbody');
|
const bodyDOM = wrapper.current.parentElement.querySelector('tbody');
|
||||||
const captionDOM = wrapper.parentElement.querySelector('caption');
|
const captionDOM = wrapper.current.parentElement.querySelector('caption');
|
||||||
|
|
||||||
let marginTop = window.getComputedStyle(headerDOM).height;
|
let marginTop = window.getComputedStyle(headerDOM).height;
|
||||||
if (captionDOM) {
|
if (captionDOM) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-overlay",
|
"name": "react-bootstrap-table2-overlay",
|
||||||
"version": "1.0.0",
|
"version": "2.0.0",
|
||||||
"description": "it's a loading overlay addons for react-bootstrap-table2",
|
"description": "it's a loading overlay addons for react-bootstrap-table2",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react-loading-overlay": "0.2.8"
|
"react-loading-overlay": "1.0.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"prop-types": "^15.0.0",
|
"prop-types": "^15.0.0",
|
||||||
|
|||||||
@@ -2,199 +2,351 @@
|
|||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
asap@~2.0.3:
|
"@babel/helper-module-imports@^7.0.0":
|
||||||
version "2.0.6"
|
version "7.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
|
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d"
|
||||||
|
integrity sha512-aP/hlLq01DWNEiDg4Jn23i+CXxW/owM4WpDLFUbpjxe4NS3BhLVZQ5i7E0ZrxuQ/vwekIeciyamgB1UIYxxM6A==
|
||||||
base64-js@^1.0.2:
|
|
||||||
version "1.2.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886"
|
|
||||||
|
|
||||||
buffer@^5.0.3:
|
|
||||||
version "5.0.8"
|
|
||||||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.0.8.tgz#84daa52e7cf2fa8ce4195bc5cf0f7809e0930b24"
|
|
||||||
dependencies:
|
dependencies:
|
||||||
base64-js "^1.0.2"
|
"@babel/types" "^7.0.0"
|
||||||
ieee754 "^1.1.4"
|
|
||||||
|
|
||||||
chain-function@^1.0.0:
|
"@babel/runtime@^7.1.2", "@babel/runtime@^7.4.2":
|
||||||
version "1.0.0"
|
version "7.4.4"
|
||||||
resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.0.tgz#0d4ab37e7e18ead0bdc47b920764118ce58733dc"
|
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.4.tgz#dc2e34982eb236803aa27a07fea6857af1b9171d"
|
||||||
|
integrity sha512-w0+uT71b6Yi7i5SE0co4NioIpSYS6lLiXvCzWzGSKvpK5vdQtCbICHMj+gbAKAOtxiV6HsVh/MBdaF9EQ6faSg==
|
||||||
core-js@^1.0.0:
|
|
||||||
version "1.2.7"
|
|
||||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
|
|
||||||
|
|
||||||
css-color-keywords@^1.0.0:
|
|
||||||
version "1.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
|
|
||||||
|
|
||||||
css-to-react-native@^2.0.3:
|
|
||||||
version "2.0.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-2.0.4.tgz#cf4cc407558b3474d4ba8be1a2cd3b6ce713101b"
|
|
||||||
dependencies:
|
dependencies:
|
||||||
css-color-keywords "^1.0.0"
|
regenerator-runtime "^0.13.2"
|
||||||
fbjs "^0.8.5"
|
|
||||||
postcss-value-parser "^3.3.0"
|
|
||||||
|
|
||||||
dom-helpers@^3.2.0:
|
"@babel/types@^7.0.0":
|
||||||
version "3.2.1"
|
version "7.4.4"
|
||||||
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.2.1.tgz#3203e07fed217bd1f424b019735582fc37b2825a"
|
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.4.4.tgz#8db9e9a629bb7c29370009b4b779ed93fe57d5f0"
|
||||||
|
integrity sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==
|
||||||
encoding@^0.1.11:
|
|
||||||
version "0.1.12"
|
|
||||||
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
|
|
||||||
dependencies:
|
dependencies:
|
||||||
iconv-lite "~0.4.13"
|
esutils "^2.0.2"
|
||||||
|
lodash "^4.17.11"
|
||||||
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
fbjs@^0.8.16, fbjs@^0.8.5, fbjs@^0.8.9:
|
"@emotion/cache@^10.0.9":
|
||||||
version "0.8.16"
|
version "10.0.9"
|
||||||
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
|
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-10.0.9.tgz#e0c7b7a289f7530edcfad4dcf3858bd2e5700a6f"
|
||||||
|
integrity sha512-f7MblpE2xoimC4fCMZ9pivmsIn7hyWRIvY75owMDi8pdOSeh+w5tH3r4hBJv/LLrwiMM7cTQURqTPcYoL5pWnw==
|
||||||
dependencies:
|
dependencies:
|
||||||
core-js "^1.0.0"
|
"@emotion/sheet" "0.9.2"
|
||||||
isomorphic-fetch "^2.1.1"
|
"@emotion/stylis" "0.8.3"
|
||||||
loose-envify "^1.0.0"
|
"@emotion/utils" "0.11.1"
|
||||||
object-assign "^4.1.0"
|
"@emotion/weak-memoize" "0.2.2"
|
||||||
promise "^7.1.1"
|
|
||||||
setimmediate "^1.0.5"
|
|
||||||
ua-parser-js "^0.7.9"
|
|
||||||
|
|
||||||
has-flag@^1.0.0:
|
"@emotion/hash@0.7.1":
|
||||||
version "1.0.0"
|
version "0.7.1"
|
||||||
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
|
resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.7.1.tgz#9833722341379fb7d67f06a4b00ab3c37913da53"
|
||||||
|
integrity sha512-OYpa/Sg+2GDX+jibUfpZVn1YqSVRpYmTLF2eyAfrFTIJSbwyIrc+YscayoykvaOME/wV4BV0Sa0yqdMrgse6mA==
|
||||||
|
|
||||||
hoist-non-react-statics@^1.2.0:
|
"@emotion/memoize@0.7.1":
|
||||||
version "1.2.0"
|
version "0.7.1"
|
||||||
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb"
|
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.1.tgz#e93c13942592cf5ef01aa8297444dc192beee52f"
|
||||||
|
integrity sha512-Qv4LTqO11jepd5Qmlp3M1YEjBumoTHcHFdgPTQ+sFlIL5myi/7xu/POwP7IRu6odBdmLXdtIs1D6TuW6kbwbbg==
|
||||||
|
|
||||||
iconv-lite@~0.4.13:
|
"@emotion/serialize@^0.11.6":
|
||||||
version "0.4.19"
|
version "0.11.6"
|
||||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
|
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.6.tgz#78be8b9ee9ff49e0196233ba6ec1c1768ba1e1fc"
|
||||||
|
integrity sha512-n4zVv2qGLmspF99jaEUwnMV0fnEGsyUMsC/8KZKUSUTZMYljHE+j+B6rSD8PIFtaUIhHaxCG2JawN6L+OgLN0Q==
|
||||||
ieee754@^1.1.4:
|
|
||||||
version "1.1.8"
|
|
||||||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"
|
|
||||||
|
|
||||||
is-function@^1.0.1:
|
|
||||||
version "1.0.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/is-function/-/is-function-1.0.1.tgz#12cfb98b65b57dd3d193a3121f5f6e2f437602b5"
|
|
||||||
|
|
||||||
is-plain-object@^2.0.1:
|
|
||||||
version "2.0.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
|
|
||||||
dependencies:
|
dependencies:
|
||||||
isobject "^3.0.1"
|
"@emotion/hash" "0.7.1"
|
||||||
|
"@emotion/memoize" "0.7.1"
|
||||||
|
"@emotion/unitless" "0.7.3"
|
||||||
|
"@emotion/utils" "0.11.1"
|
||||||
|
csstype "^2.5.7"
|
||||||
|
|
||||||
is-stream@^1.0.1:
|
"@emotion/sheet@0.9.2":
|
||||||
|
version "0.9.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-0.9.2.tgz#74e5c6b5e489a1ba30ab246ab5eedd96916487c4"
|
||||||
|
integrity sha512-pVBLzIbC/QCHDKJF2E82V2H/W/B004mDFQZiyo/MSR+VC4pV5JLG0TF/zgQDFvP3fZL/5RTPGEmXlYJBMUuJ+A==
|
||||||
|
|
||||||
|
"@emotion/stylis@0.8.3":
|
||||||
|
version "0.8.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@emotion/stylis/-/stylis-0.8.3.tgz#3ca7e9bcb31b3cb4afbaeb66156d86ee85e23246"
|
||||||
|
integrity sha512-M3nMfJ6ndJMYloSIbYEBq6G3eqoYD41BpDOxreE8j0cb4fzz/5qvmqU9Mb2hzsXcCnIlGlWhS03PCzVGvTAe0Q==
|
||||||
|
|
||||||
|
"@emotion/unitless@0.7.3":
|
||||||
|
version "0.7.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.7.3.tgz#6310a047f12d21a1036fb031317219892440416f"
|
||||||
|
integrity sha512-4zAPlpDEh2VwXswwr/t8xGNDGg8RQiPxtxZ3qQEXyQsBV39ptTdESCjuBvGze1nLMVrxmTIKmnO/nAV8Tqjjzg==
|
||||||
|
|
||||||
|
"@emotion/utils@0.11.1":
|
||||||
|
version "0.11.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.11.1.tgz#8529b7412a6eb4b48bdf6e720cc1b8e6e1e17628"
|
||||||
|
integrity sha512-8M3VN0hetwhsJ8dH8VkVy7xo5/1VoBsDOk/T4SJOeXwTO1c4uIqVNx2qyecLFnnUWD5vvUqHQ1gASSeUN6zcTg==
|
||||||
|
|
||||||
|
"@emotion/weak-memoize@0.2.2":
|
||||||
|
version "0.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.2.tgz#63985d3d8b02530e0869962f4da09142ee8e200e"
|
||||||
|
integrity sha512-n/VQ4mbfr81aqkx/XmVicOLjviMuy02eenSdJY33SVA7S2J42EU0P1H0mOogfYedb3wXA0d/LVtBrgTSm04WEA==
|
||||||
|
|
||||||
|
argparse@^1.0.7:
|
||||||
|
version "1.0.10"
|
||||||
|
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
|
||||||
|
integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
|
||||||
|
dependencies:
|
||||||
|
sprintf-js "~1.0.2"
|
||||||
|
|
||||||
|
babel-plugin-emotion@^10.0.9:
|
||||||
|
version "10.0.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.9.tgz#04a0404d5a4084d5296357a393d344c0f8303ae4"
|
||||||
|
integrity sha512-IfWP12e9/wHtWHxVTzD692Nbcmrmcz2tip7acp6YUqtrP7slAyr5B+69hyZ8jd55GsyNSZwryNnmuDEVe0j+7w==
|
||||||
|
dependencies:
|
||||||
|
"@babel/helper-module-imports" "^7.0.0"
|
||||||
|
"@emotion/hash" "0.7.1"
|
||||||
|
"@emotion/memoize" "0.7.1"
|
||||||
|
"@emotion/serialize" "^0.11.6"
|
||||||
|
babel-plugin-macros "^2.0.0"
|
||||||
|
babel-plugin-syntax-jsx "^6.18.0"
|
||||||
|
convert-source-map "^1.5.0"
|
||||||
|
escape-string-regexp "^1.0.5"
|
||||||
|
find-root "^1.1.0"
|
||||||
|
source-map "^0.5.7"
|
||||||
|
|
||||||
|
babel-plugin-macros@^2.0.0:
|
||||||
|
version "2.5.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-2.5.1.tgz#4a119ac2c2e19b458c259b9accd7ee34fd57ec6f"
|
||||||
|
integrity sha512-xN3KhAxPzsJ6OQTktCanNpIFnnMsCV+t8OloKxIL72D6+SUZYFn9qfklPgef5HyyDtzYZqqb+fs1S12+gQY82Q==
|
||||||
|
dependencies:
|
||||||
|
"@babel/runtime" "^7.4.2"
|
||||||
|
cosmiconfig "^5.2.0"
|
||||||
|
resolve "^1.10.0"
|
||||||
|
|
||||||
|
babel-plugin-syntax-jsx@^6.18.0:
|
||||||
|
version "6.18.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
|
||||||
|
integrity sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY=
|
||||||
|
|
||||||
|
caller-callsite@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/caller-callsite/-/caller-callsite-2.0.0.tgz#847e0fce0a223750a9a027c54b33731ad3154134"
|
||||||
|
integrity sha1-hH4PzgoiN1CpoCfFSzNzGtMVQTQ=
|
||||||
|
dependencies:
|
||||||
|
callsites "^2.0.0"
|
||||||
|
|
||||||
|
caller-path@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-2.0.0.tgz#468f83044e369ab2010fac5f06ceee15bb2cb1f4"
|
||||||
|
integrity sha1-Ro+DBE42mrIBD6xfBs7uFbsssfQ=
|
||||||
|
dependencies:
|
||||||
|
caller-callsite "^2.0.0"
|
||||||
|
|
||||||
|
callsites@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50"
|
||||||
|
integrity sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=
|
||||||
|
|
||||||
|
convert-source-map@^1.5.0:
|
||||||
|
version "1.6.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20"
|
||||||
|
integrity sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==
|
||||||
|
dependencies:
|
||||||
|
safe-buffer "~5.1.1"
|
||||||
|
|
||||||
|
cosmiconfig@^5.2.0:
|
||||||
|
version "5.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
|
||||||
|
integrity sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==
|
||||||
|
dependencies:
|
||||||
|
import-fresh "^2.0.0"
|
||||||
|
is-directory "^0.3.1"
|
||||||
|
js-yaml "^3.13.1"
|
||||||
|
parse-json "^4.0.0"
|
||||||
|
|
||||||
|
create-emotion@^10.0.9:
|
||||||
|
version "10.0.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/create-emotion/-/create-emotion-10.0.9.tgz#290c2036126171c9566fa24f49c9241d54625138"
|
||||||
|
integrity sha512-sLKD4bIiTs8PpEqr5vlCoV5lsYE4QOBYEUWaD0R+VGRMCvBKHmYlvLJXsL99Kdc4YEFAFwipi2bbncnvv6UxRg==
|
||||||
|
dependencies:
|
||||||
|
"@emotion/cache" "^10.0.9"
|
||||||
|
"@emotion/serialize" "^0.11.6"
|
||||||
|
"@emotion/sheet" "0.9.2"
|
||||||
|
"@emotion/utils" "0.11.1"
|
||||||
|
|
||||||
|
csstype@^2.5.7:
|
||||||
|
version "2.6.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.4.tgz#d585a6062096e324e7187f80e04f92bd0f00e37f"
|
||||||
|
integrity sha512-lAJUJP3M6HxFXbqtGRc0iZrdyeN+WzOWeY0q/VnFzI+kqVrYIzC7bWlKqCW7oCIdzoPkvfp82EVvrTlQ8zsWQg==
|
||||||
|
|
||||||
|
dom-helpers@^3.4.0:
|
||||||
|
version "3.4.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.4.0.tgz#e9b369700f959f62ecde5a6babde4bccd9169af8"
|
||||||
|
integrity sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==
|
||||||
|
dependencies:
|
||||||
|
"@babel/runtime" "^7.1.2"
|
||||||
|
|
||||||
|
emotion@^10.0.1:
|
||||||
|
version "10.0.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/emotion/-/emotion-10.0.9.tgz#2c37598af13df31dcd35a1957eaa8830f368c066"
|
||||||
|
integrity sha512-IMFwwWlU2TDt7eh4v6dm58E8VHAYOitqRbVoazQdxIu9/0CAH4a3UrTMnZSlWQAo09MrRRlKfgQFHswnj40meQ==
|
||||||
|
dependencies:
|
||||||
|
babel-plugin-emotion "^10.0.9"
|
||||||
|
create-emotion "^10.0.9"
|
||||||
|
|
||||||
|
error-ex@^1.3.1:
|
||||||
|
version "1.3.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
|
||||||
|
integrity sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==
|
||||||
|
dependencies:
|
||||||
|
is-arrayish "^0.2.1"
|
||||||
|
|
||||||
|
escape-string-regexp@^1.0.5:
|
||||||
|
version "1.0.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||||
|
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
|
||||||
|
|
||||||
|
esprima@^4.0.0:
|
||||||
|
version "4.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
|
||||||
|
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
|
||||||
|
|
||||||
|
esutils@^2.0.2:
|
||||||
|
version "2.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
|
||||||
|
integrity sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=
|
||||||
|
|
||||||
|
find-root@^1.1.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
|
resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4"
|
||||||
|
integrity sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==
|
||||||
|
|
||||||
isobject@^3.0.1:
|
import-fresh@^2.0.0:
|
||||||
version "3.0.1"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
|
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-2.0.0.tgz#d81355c15612d386c61f9ddd3922d4304822a546"
|
||||||
|
integrity sha1-2BNVwVYS04bGH53dOSLUMEgipUY=
|
||||||
isomorphic-fetch@^2.1.1:
|
|
||||||
version "2.2.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
|
|
||||||
dependencies:
|
dependencies:
|
||||||
node-fetch "^1.0.1"
|
caller-path "^2.0.0"
|
||||||
whatwg-fetch ">=0.10.0"
|
resolve-from "^3.0.0"
|
||||||
|
|
||||||
js-tokens@^3.0.0:
|
is-arrayish@^0.2.1:
|
||||||
version "3.0.2"
|
version "0.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
|
||||||
|
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=
|
||||||
|
|
||||||
loose-envify@^1.0.0, loose-envify@^1.3.1:
|
is-directory@^0.3.1:
|
||||||
version "1.3.1"
|
version "0.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
|
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
|
||||||
|
integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=
|
||||||
|
|
||||||
|
"js-tokens@^3.0.0 || ^4.0.0":
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
|
||||||
|
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
|
||||||
|
|
||||||
|
js-yaml@^3.13.1:
|
||||||
|
version "3.13.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
|
||||||
|
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
|
||||||
dependencies:
|
dependencies:
|
||||||
js-tokens "^3.0.0"
|
argparse "^1.0.7"
|
||||||
|
esprima "^4.0.0"
|
||||||
|
|
||||||
node-fetch@^1.0.1:
|
json-parse-better-errors@^1.0.1:
|
||||||
version "1.7.3"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
|
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
|
||||||
|
integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==
|
||||||
|
|
||||||
|
lodash@^4.17.11:
|
||||||
|
version "4.17.11"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
|
||||||
|
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
|
||||||
|
|
||||||
|
loose-envify@^1.4.0:
|
||||||
|
version "1.4.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||||
|
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
|
||||||
dependencies:
|
dependencies:
|
||||||
encoding "^0.1.11"
|
js-tokens "^3.0.0 || ^4.0.0"
|
||||||
is-stream "^1.0.1"
|
|
||||||
|
|
||||||
object-assign@^4.1.0, object-assign@^4.1.1:
|
object-assign@^4.1.1:
|
||||||
version "4.1.1"
|
version "4.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
||||||
|
|
||||||
postcss-value-parser@^3.3.0:
|
parse-json@^4.0.0:
|
||||||
version "3.3.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-3.3.0.tgz#87f38f9f18f774a4ab4c8a232f5c5ce8872a9d15"
|
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
|
||||||
|
integrity sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=
|
||||||
promise@^7.1.1:
|
|
||||||
version "7.3.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
|
|
||||||
dependencies:
|
dependencies:
|
||||||
asap "~2.0.3"
|
error-ex "^1.3.1"
|
||||||
|
json-parse-better-errors "^1.0.1"
|
||||||
|
|
||||||
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6:
|
path-parse@^1.0.6:
|
||||||
version "15.6.0"
|
version "1.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.0.tgz#ceaf083022fc46b4a35f69e13ef75aed0d639856"
|
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
|
||||||
|
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
|
||||||
|
|
||||||
|
prop-types@^15.6.2:
|
||||||
|
version "15.7.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
|
||||||
|
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
fbjs "^0.8.16"
|
loose-envify "^1.4.0"
|
||||||
loose-envify "^1.3.1"
|
|
||||||
object-assign "^4.1.1"
|
object-assign "^4.1.1"
|
||||||
|
react-is "^16.8.1"
|
||||||
|
|
||||||
react-loading-overlay@0.2.8:
|
react-is@^16.8.1:
|
||||||
version "0.2.8"
|
version "16.8.6"
|
||||||
resolved "https://registry.yarnpkg.com/react-loading-overlay/-/react-loading-overlay-0.2.8.tgz#c1c5531c9cfa4be6caca6b9aa0c1eb19e22b03fe"
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
|
||||||
|
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
|
||||||
|
|
||||||
|
react-lifecycles-compat@^3.0.4:
|
||||||
|
version "3.0.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
|
||||||
|
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
|
||||||
|
|
||||||
|
react-loading-overlay@1.0.1:
|
||||||
|
version "1.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/react-loading-overlay/-/react-loading-overlay-1.0.1.tgz#ee3b1ad56c45bb2f1ba46d4820ba0d06cd319a91"
|
||||||
|
integrity sha512-aUjtZ8tNXBSx+MbD2SQs0boPbeTAGTh+I5U9nWjDzMasKlYr58RJpr57c8W7uApeLpOkAGbInExRi6GamNC2bA==
|
||||||
dependencies:
|
dependencies:
|
||||||
prop-types "^15.5.10"
|
emotion "^10.0.1"
|
||||||
react-transition-group "^1.2.1"
|
prop-types "^15.6.2"
|
||||||
styled-components "^2.1.2"
|
react-transition-group "^2.5.0"
|
||||||
|
|
||||||
react-transition-group@^1.2.1:
|
react-transition-group@^2.5.0:
|
||||||
version "1.2.1"
|
version "2.9.0"
|
||||||
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.2.1.tgz#e11f72b257f921b213229a774df46612346c7ca6"
|
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-2.9.0.tgz#df9cdb025796211151a436c69a8f3b97b5b07c8d"
|
||||||
|
integrity sha512-+HzNTCHpeQyl4MJ/bdE0u6XRMe9+XG/+aL4mCxVN4DnPBQ0/5bfHWPDuOZUzYdMj94daZaZdCCc1Dzt9R/xSSg==
|
||||||
dependencies:
|
dependencies:
|
||||||
chain-function "^1.0.0"
|
dom-helpers "^3.4.0"
|
||||||
dom-helpers "^3.2.0"
|
loose-envify "^1.4.0"
|
||||||
loose-envify "^1.3.1"
|
prop-types "^15.6.2"
|
||||||
prop-types "^15.5.6"
|
react-lifecycles-compat "^3.0.4"
|
||||||
warning "^3.0.0"
|
|
||||||
|
|
||||||
setimmediate@^1.0.5:
|
regenerator-runtime@^0.13.2:
|
||||||
version "1.0.5"
|
version "0.13.2"
|
||||||
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
|
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447"
|
||||||
|
integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==
|
||||||
|
|
||||||
styled-components@^2.1.2:
|
resolve-from@^3.0.0:
|
||||||
version "2.2.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-2.2.4.tgz#dd87fd3dafd359e7a0d570aec1bd07d691c0b5a2"
|
|
||||||
dependencies:
|
|
||||||
buffer "^5.0.3"
|
|
||||||
css-to-react-native "^2.0.3"
|
|
||||||
fbjs "^0.8.9"
|
|
||||||
hoist-non-react-statics "^1.2.0"
|
|
||||||
is-function "^1.0.1"
|
|
||||||
is-plain-object "^2.0.1"
|
|
||||||
prop-types "^15.5.4"
|
|
||||||
stylis "^3.4.0"
|
|
||||||
supports-color "^3.2.3"
|
|
||||||
|
|
||||||
stylis@^3.4.0:
|
|
||||||
version "3.4.5"
|
|
||||||
resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.4.5.tgz#d7b9595fc18e7b9c8775eca8270a9a1d3e59806e"
|
|
||||||
|
|
||||||
supports-color@^3.2.3:
|
|
||||||
version "3.2.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6"
|
|
||||||
dependencies:
|
|
||||||
has-flag "^1.0.0"
|
|
||||||
|
|
||||||
ua-parser-js@^0.7.9:
|
|
||||||
version "0.7.17"
|
|
||||||
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"
|
|
||||||
|
|
||||||
warning@^3.0.0:
|
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
|
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
|
||||||
dependencies:
|
integrity sha1-six699nWiBvItuZTM17rywoYh0g=
|
||||||
loose-envify "^1.0.0"
|
|
||||||
|
|
||||||
whatwg-fetch@>=0.10.0:
|
resolve@^1.10.0:
|
||||||
version "2.0.3"
|
version "1.11.0"
|
||||||
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84"
|
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.11.0.tgz#4014870ba296176b86343d50b60f3b50609ce232"
|
||||||
|
integrity sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==
|
||||||
|
dependencies:
|
||||||
|
path-parse "^1.0.6"
|
||||||
|
|
||||||
|
safe-buffer@~5.1.1:
|
||||||
|
version "5.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
|
||||||
|
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
|
||||||
|
|
||||||
|
source-map@^0.5.7:
|
||||||
|
version "0.5.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
|
||||||
|
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
|
||||||
|
|
||||||
|
sprintf-js@~1.0.2:
|
||||||
|
version "1.0.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||||
|
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
|
||||||
|
|
||||||
|
to-fast-properties@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
|
||||||
|
integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-paginator",
|
"name": "react-bootstrap-table2-paginator",
|
||||||
"version": "2.0.6",
|
"version": "2.1.0",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ class PaginationDataProvider extends Provider {
|
|||||||
isRemotePagination: PropTypes.func.isRequired
|
isRemotePagination: PropTypes.func.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
// eslint-disable-next-line camelcase, react/sort-comp
|
||||||
super.componentWillReceiveProps(nextProps);
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
super.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
const { currSizePerPage } = this;
|
const { currSizePerPage } = this;
|
||||||
const { custom, onPageChange } = nextProps.pagination.options;
|
const { custom, onPageChange } = nextProps.pagination.options;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,11 @@ class PageButton extends Component {
|
|||||||
|
|
||||||
PageButton.propTypes = {
|
PageButton.propTypes = {
|
||||||
onPageChange: PropTypes.func.isRequired,
|
onPageChange: PropTypes.func.isRequired,
|
||||||
page: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
page: PropTypes.oneOfType([
|
||||||
|
PropTypes.node,
|
||||||
|
PropTypes.number,
|
||||||
|
PropTypes.string
|
||||||
|
]).isRequired,
|
||||||
active: PropTypes.bool.isRequired,
|
active: PropTypes.bool.isRequired,
|
||||||
disabled: PropTypes.bool.isRequired,
|
disabled: PropTypes.bool.isRequired,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
import pageResolver from './page-resolver';
|
import pageResolver from './page-resolver';
|
||||||
@@ -12,7 +13,7 @@ export default WrappedComponent =>
|
|||||||
this.state = this.initialState();
|
this.state = this.initialState();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
const { dataSize, currSizePerPage } = nextProps;
|
const { dataSize, currSizePerPage } = nextProps;
|
||||||
if (currSizePerPage !== this.props.currSizePerPage || dataSize !== this.props.dataSize) {
|
if (currSizePerPage !== this.props.currSizePerPage || dataSize !== this.props.dataSize) {
|
||||||
const totalPages = this.calculateTotalPage(currSizePerPage, dataSize);
|
const totalPages = this.calculateTotalPage(currSizePerPage, dataSize);
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ const PaginatonList = props => (
|
|||||||
|
|
||||||
PaginatonList.propTypes = {
|
PaginatonList.propTypes = {
|
||||||
pages: PropTypes.arrayOf(PropTypes.shape({
|
pages: PropTypes.arrayOf(PropTypes.shape({
|
||||||
page: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
page: PropTypes.oneOfType([
|
||||||
|
PropTypes.node,
|
||||||
|
PropTypes.number,
|
||||||
|
PropTypes.string
|
||||||
|
]),
|
||||||
active: PropTypes.bool,
|
active: PropTypes.bool,
|
||||||
disable: PropTypes.bool,
|
disable: PropTypes.bool,
|
||||||
title: PropTypes.string
|
title: PropTypes.string
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ Pagination.propTypes = {
|
|||||||
sizePerPageRenderer: PropTypes.func,
|
sizePerPageRenderer: PropTypes.func,
|
||||||
paginationTotalRenderer: PropTypes.func,
|
paginationTotalRenderer: PropTypes.func,
|
||||||
sizePerPageOptionRenderer: PropTypes.func,
|
sizePerPageOptionRenderer: PropTypes.func,
|
||||||
firstPageText: PropTypes.string,
|
firstPageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
prePageText: PropTypes.string,
|
prePageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
nextPageText: PropTypes.string,
|
nextPageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
lastPageText: PropTypes.string,
|
lastPageText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
nextPageTitle: PropTypes.string,
|
nextPageTitle: PropTypes.string,
|
||||||
prePageTitle: PropTypes.string,
|
prePageTitle: PropTypes.string,
|
||||||
firstPageTitle: PropTypes.string,
|
firstPageTitle: PropTypes.string,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
/* eslint no-lonely-if: 0 */
|
/* eslint no-lonely-if: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import Const from './const';
|
import Const from './const';
|
||||||
@@ -45,23 +46,6 @@ class StateProvider extends React.Component {
|
|||||||
this.dataChangeListener.on('filterChanged', this.handleDataSizeChange);
|
this.dataChangeListener.on('filterChanged', this.handleDataSizeChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
const { custom } = nextProps.pagination.options;
|
|
||||||
|
|
||||||
// user should align the page when the page is not fit to the data size when remote enable
|
|
||||||
if (this.isRemotePagination() || custom) {
|
|
||||||
if (typeof nextProps.pagination.options.page !== 'undefined') {
|
|
||||||
this.currPage = nextProps.pagination.options.page;
|
|
||||||
}
|
|
||||||
if (typeof nextProps.pagination.options.sizePerPage !== 'undefined') {
|
|
||||||
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
|
|
||||||
}
|
|
||||||
if (typeof nextProps.pagination.options.totalSize !== 'undefined') {
|
|
||||||
this.dataSize = nextProps.pagination.options.totalSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getPaginationProps = () => {
|
getPaginationProps = () => {
|
||||||
const { pagination: { options }, bootstrap4 } = this.props;
|
const { pagination: { options }, bootstrap4 } = this.props;
|
||||||
const { currPage, currSizePerPage, dataSize } = this;
|
const { currPage, currSizePerPage, dataSize } = this;
|
||||||
@@ -113,6 +97,23 @@ class StateProvider extends React.Component {
|
|||||||
|
|
||||||
getPaginationRemoteEmitter = () => this.remoteEmitter || this.props.remoteEmitter;
|
getPaginationRemoteEmitter = () => this.remoteEmitter || this.props.remoteEmitter;
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
const { custom } = nextProps.pagination.options;
|
||||||
|
|
||||||
|
// user should align the page when the page is not fit to the data size when remote enable
|
||||||
|
if (this.isRemotePagination() || custom) {
|
||||||
|
if (typeof nextProps.pagination.options.page !== 'undefined') {
|
||||||
|
this.currPage = nextProps.pagination.options.page;
|
||||||
|
}
|
||||||
|
if (typeof nextProps.pagination.options.sizePerPage !== 'undefined') {
|
||||||
|
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
|
||||||
|
}
|
||||||
|
if (typeof nextProps.pagination.options.totalSize !== 'undefined') {
|
||||||
|
this.dataSize = nextProps.pagination.options.totalSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isRemotePagination = () => {
|
isRemotePagination = () => {
|
||||||
const e = {};
|
const e = {};
|
||||||
this.remoteEmitter.emit('isRemotePagination', e);
|
this.remoteEmitter.emit('isRemotePagination', e);
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ describe('PaginationDataContext', () => {
|
|||||||
data: [],
|
data: [],
|
||||||
pagination: { ...defaultPagination }
|
pagination: { ...defaultPagination }
|
||||||
};
|
};
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset currPage to first page', () => {
|
it('should reset currPage to first page', () => {
|
||||||
@@ -195,7 +195,7 @@ describe('PaginationDataContext', () => {
|
|||||||
data: [],
|
data: [],
|
||||||
pagination: { ...defaultPagination, options: { onPageChange } }
|
pagination: { ...defaultPagination, options: { onPageChange } }
|
||||||
};
|
};
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call options.onPageChange correctly', () => {
|
it('should call options.onPageChange correctly', () => {
|
||||||
|
|||||||
@@ -164,13 +164,13 @@ describe('paginationHandler', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setting correct state.totalPages', () => {
|
it('should setting correct state.totalPages', () => {
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
expect(instance.state.totalPages).toEqual(
|
expect(instance.state.totalPages).toEqual(
|
||||||
instance.calculateTotalPage(nextProps.currSizePerPage));
|
instance.calculateTotalPage(nextProps.currSizePerPage));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should setting correct state.lastPage', () => {
|
it('should setting correct state.lastPage', () => {
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
const totalPages = instance.calculateTotalPage(nextProps.currSizePerPage);
|
const totalPages = instance.calculateTotalPage(nextProps.currSizePerPage);
|
||||||
expect(instance.state.lastPage).toEqual(
|
expect(instance.state.lastPage).toEqual(
|
||||||
instance.calculateLastPage(totalPages));
|
instance.calculateLastPage(totalPages));
|
||||||
@@ -186,13 +186,13 @@ describe('paginationHandler', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setting correct state.totalPages', () => {
|
it('should setting correct state.totalPages', () => {
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
expect(instance.state.totalPages).toEqual(
|
expect(instance.state.totalPages).toEqual(
|
||||||
instance.calculateTotalPage(nextProps.currSizePerPage, nextProps.dataSize));
|
instance.calculateTotalPage(nextProps.currSizePerPage, nextProps.dataSize));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should setting correct state.lastPage', () => {
|
it('should setting correct state.lastPage', () => {
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
const totalPages = instance.calculateTotalPage(
|
const totalPages = instance.calculateTotalPage(
|
||||||
nextProps.currSizePerPage, nextProps.dataSize);
|
nextProps.currSizePerPage, nextProps.dataSize);
|
||||||
expect(instance.state.lastPage).toEqual(
|
expect(instance.state.lastPage).toEqual(
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ describe('PaginationStateContext', () => {
|
|||||||
data,
|
data,
|
||||||
pagination: { ...defaultPagination, options: { page: 3, sizePerPage: 5, totalSize: 50 } }
|
pagination: { ...defaultPagination, options: { page: 3, sizePerPage: 5, totalSize: 50 } }
|
||||||
};
|
};
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should always reset currPage and currSizePerPage', () => {
|
it('should always reset currPage and currSizePerPage', () => {
|
||||||
@@ -181,7 +181,7 @@ describe('PaginationStateContext', () => {
|
|||||||
options: { page: 3, sizePerPage: 5, custom: true, totalSize: 50 }
|
options: { page: 3, sizePerPage: 5, custom: true, totalSize: 50 }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
instance.componentWillReceiveProps(nextProps);
|
instance.UNSAFE_componentWillReceiveProps(nextProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should always reset currPage and currSizePerPage', () => {
|
it('should always reset currPage and currSizePerPage', () => {
|
||||||
|
|||||||
@@ -98,6 +98,33 @@ Accept a string that will be used for default searching when first time table re
|
|||||||
</ToolkitProvider>
|
</ToolkitProvider>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### onColumnMatch - [function]
|
||||||
|
Acccpt a function which will be called when table try to match every cells when search happening. This function accept an object like below example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function onColumnMatch({
|
||||||
|
searchText,
|
||||||
|
value,
|
||||||
|
column,
|
||||||
|
row
|
||||||
|
}) {
|
||||||
|
// implement your custom match logic on every cell value
|
||||||
|
}
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search={ {
|
||||||
|
onColumnMatch
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
// ...
|
||||||
|
</ToolkitProvider>
|
||||||
|
```
|
||||||
|
|
||||||
|
> Notes: You have to return `true` when your match logic is positive and vice versa.
|
||||||
|
|
||||||
#### searchFormatted - [bool]
|
#### searchFormatted - [bool]
|
||||||
If you want to search on the formatted data, you are supposed to enable this props. `react-bootstrap-table2` will check if you define the `column.formatter` when doing search.
|
If you want to search on the formatted data, you are supposed to enable this props. `react-bootstrap-table2` will check if you define the `column.formatter` when doing search.
|
||||||
|
|
||||||
@@ -182,9 +209,15 @@ Custom the csv file separator.
|
|||||||
#### ignoreHeader - [bool]
|
#### ignoreHeader - [bool]
|
||||||
Default is `false`. Give true to avoid to attach the csv header.
|
Default is `false`. Give true to avoid to attach the csv header.
|
||||||
|
|
||||||
|
#### ignoreFooter - [bool]
|
||||||
|
Default is `true`. Give `false` to attach the table footer if enabled.
|
||||||
|
|
||||||
#### noAutoBOM - [bool]
|
#### noAutoBOM - [bool]
|
||||||
Default is `true`.
|
Default is `true`.
|
||||||
|
|
||||||
|
#### blobType - [string]
|
||||||
|
Default is `text/plain;charset=utf-8`. Change to update the blob type of the exported file.
|
||||||
|
|
||||||
#### exportAll - [bool]
|
#### exportAll - [bool]
|
||||||
Default is `true`. `false` will only export current data which display on table.
|
Default is `true`. `false` will only export current data which display on table.
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
|
|||||||
fileName: PropTypes.string,
|
fileName: PropTypes.string,
|
||||||
separator: PropTypes.string,
|
separator: PropTypes.string,
|
||||||
ignoreHeader: PropTypes.bool,
|
ignoreHeader: PropTypes.bool,
|
||||||
|
ignoreFooter: PropTypes.bool,
|
||||||
noAutoBOM: PropTypes.bool,
|
noAutoBOM: PropTypes.bool,
|
||||||
|
blobType: PropTypes.string,
|
||||||
exportAll: PropTypes.bool,
|
exportAll: PropTypes.bool,
|
||||||
onlyExportFiltered: PropTypes.bool,
|
onlyExportFiltered: PropTypes.bool,
|
||||||
onlyExportSelection: PropTypes.bool
|
onlyExportSelection: PropTypes.bool
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-toolkit",
|
"name": "react-bootstrap-table2-toolkit",
|
||||||
"version": "1.4.1",
|
"version": "2.1.1",
|
||||||
"description": "The toolkit for react-bootstrap-table2",
|
"description": "The toolkit for react-bootstrap-table2",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -45,6 +45,6 @@
|
|||||||
"react-dom": "^16.3.0"
|
"react-dom": "^16.3.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"file-saver": "1.3.8"
|
"file-saver": "2.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,17 +12,21 @@ export const getMetaInfo = columns =>
|
|||||||
export: column.csvExport === false ? false : true,
|
export: column.csvExport === false ? false : true,
|
||||||
row: Number(column.row) || 0,
|
row: Number(column.row) || 0,
|
||||||
rowSpan: Number(column.rowSpan) || 1,
|
rowSpan: Number(column.rowSpan) || 1,
|
||||||
colSpan: Number(column.colSpan) || 1
|
colSpan: Number(column.colSpan) || 1,
|
||||||
|
footer: column.footer,
|
||||||
|
footerFormatter: column.footerFormatter
|
||||||
}))
|
}))
|
||||||
.filter(_ => _.export);
|
.filter(_ => _.export);
|
||||||
|
|
||||||
export const transform = (
|
export const transform = (
|
||||||
data,
|
data,
|
||||||
meta,
|
meta,
|
||||||
getValue,
|
columns,
|
||||||
|
_,
|
||||||
{
|
{
|
||||||
separator,
|
separator,
|
||||||
ignoreHeader
|
ignoreHeader,
|
||||||
|
ignoreFooter
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const visibleColumns = meta.filter(m => m.export);
|
const visibleColumns = meta.filter(m => m.export);
|
||||||
@@ -37,16 +41,28 @@ export const transform = (
|
|||||||
content += data
|
content += data
|
||||||
.map((row, rowIndex) =>
|
.map((row, rowIndex) =>
|
||||||
visibleColumns.map((m) => {
|
visibleColumns.map((m) => {
|
||||||
let cellContent = getValue(row, m.field);
|
let cellContent = _.get(row, m.field);
|
||||||
if (m.formatter) {
|
if (m.formatter) {
|
||||||
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
||||||
}
|
}
|
||||||
if (m.type === String) {
|
if (m.type === String) {
|
||||||
return `"${cellContent}"`;
|
return `"${`${cellContent}`.replace(/"/g, '""')}"`;
|
||||||
}
|
}
|
||||||
return cellContent;
|
return cellContent;
|
||||||
}).join(separator)).join('\n');
|
}).join(separator)).join('\n');
|
||||||
|
|
||||||
|
if (!ignoreFooter) {
|
||||||
|
content += '\n';
|
||||||
|
content += visibleColumns.map((m, i) => {
|
||||||
|
if (typeof m.footer === 'function') {
|
||||||
|
const columnData = _.pluck(data, columns[i].dataField);
|
||||||
|
return `"${m.footer(columnData, columns[i], i)}"`;
|
||||||
|
} else if (m.footerFormatter) {
|
||||||
|
return `"${m.footerFormatter(columns[i], i)}"`;
|
||||||
|
}
|
||||||
|
return `"${m.footer}"`;
|
||||||
|
}).join(separator);
|
||||||
|
}
|
||||||
return content;
|
return content;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,11 +70,12 @@ export const save = (
|
|||||||
content,
|
content,
|
||||||
{
|
{
|
||||||
noAutoBOM,
|
noAutoBOM,
|
||||||
fileName
|
fileName,
|
||||||
|
blobType
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
FileSaver.saveAs(
|
FileSaver.saveAs(
|
||||||
new Blob([content], { type: 'text/plain;charset=utf-8' }),
|
new Blob([content], { type: blobType }),
|
||||||
fileName,
|
fileName,
|
||||||
noAutoBOM
|
noAutoBOM
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ const csvDefaultOptions = {
|
|||||||
fileName: 'spreadsheet.csv',
|
fileName: 'spreadsheet.csv',
|
||||||
separator: ',',
|
separator: ',',
|
||||||
ignoreHeader: false,
|
ignoreHeader: false,
|
||||||
|
ignoreFooter: true,
|
||||||
noAutoBOM: true,
|
noAutoBOM: true,
|
||||||
|
blobType: 'text/plain;charset=utf-8',
|
||||||
exportAll: true,
|
exportAll: true,
|
||||||
onlyExportSelection: false
|
onlyExportSelection: false
|
||||||
};
|
};
|
||||||
@@ -45,7 +47,7 @@ export default Base =>
|
|||||||
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = transform(data, meta, this._.get, options);
|
const content = transform(data, meta, columns, this._, options);
|
||||||
save(content, options);
|
save(content, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
@@ -34,10 +35,6 @@ class SearchBar extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
this.setState({ value: nextProps.searchText });
|
|
||||||
}
|
|
||||||
|
|
||||||
onChangeValue = (e) => {
|
onChangeValue = (e) => {
|
||||||
this.setState({ value: e.target.value });
|
this.setState({ value: e.target.value });
|
||||||
}
|
}
|
||||||
@@ -50,6 +47,10 @@ class SearchBar extends React.Component {
|
|||||||
debounceCallback();
|
debounceCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
this.setState({ value: nextProps.searchText });
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
className,
|
className,
|
||||||
@@ -69,6 +70,7 @@ class SearchBar extends React.Component {
|
|||||||
id={ `search-bar-${tableId}` }
|
id={ `search-bar-${tableId}` }
|
||||||
type="text"
|
type="text"
|
||||||
style={ style }
|
style={ style }
|
||||||
|
aria-label="enter text you want to search"
|
||||||
onKeyUp={ () => this.onKeyup() }
|
onKeyUp={ () => this.onKeyup() }
|
||||||
onChange={ this.onChangeValue }
|
onChange={ this.onChangeValue }
|
||||||
className={ `form-control ${className}` }
|
className={ `form-control ${className}` }
|
||||||
@@ -96,7 +98,7 @@ SearchBar.defaultProps = {
|
|||||||
placeholder: 'Search',
|
placeholder: 'Search',
|
||||||
delay: 250,
|
delay: 250,
|
||||||
searchText: '',
|
searchText: '',
|
||||||
tableId: 0
|
tableId: '0'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SearchBar;
|
export default SearchBar;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
/* eslint no-continue: 0 */
|
/* eslint no-continue: 0 */
|
||||||
/* eslint no-lonely-if: 0 */
|
/* eslint no-lonely-if: 0 */
|
||||||
/* eslint class-methods-use-this: 0 */
|
/* eslint class-methods-use-this: 0 */
|
||||||
|
/* eslint camelcase: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
export default (options = {
|
export default (options = {
|
||||||
searchFormatted: false
|
searchFormatted: false,
|
||||||
|
onColumnMatch: null
|
||||||
}) => (
|
}) => (
|
||||||
_,
|
_,
|
||||||
isRemoteSearch,
|
isRemoteSearch,
|
||||||
@@ -35,7 +37,17 @@ export default (options = {
|
|||||||
this.state = { data: initialData };
|
this.state = { data: initialData };
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
getSearched() {
|
||||||
|
return this.state.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
triggerListener(result) {
|
||||||
|
if (this.props.dataChangeListener) {
|
||||||
|
this.props.dataChangeListener.emit('filterChanged', result.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.searchText !== this.props.searchText) {
|
if (nextProps.searchText !== this.props.searchText) {
|
||||||
if (isRemoteSearch()) {
|
if (isRemoteSearch()) {
|
||||||
handleRemoteSearchChange(nextProps.searchText);
|
handleRemoteSearchChange(nextProps.searchText);
|
||||||
@@ -59,16 +71,6 @@ export default (options = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSearched() {
|
|
||||||
return this.state.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerListener(result) {
|
|
||||||
if (this.props.dataChangeListener) {
|
|
||||||
this.props.dataChangeListener.emit('filterChanged', result.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
search(props) {
|
search(props) {
|
||||||
const { data, columns } = props;
|
const { data, columns } = props;
|
||||||
const searchText = props.searchText.toLowerCase();
|
const searchText = props.searchText.toLowerCase();
|
||||||
@@ -82,11 +84,22 @@ export default (options = {
|
|||||||
} else if (column.filterValue) {
|
} else if (column.filterValue) {
|
||||||
targetValue = column.filterValue(targetValue, row);
|
targetValue = column.filterValue(targetValue, row);
|
||||||
}
|
}
|
||||||
if (targetValue !== null && typeof targetValue !== 'undefined') {
|
if (options.onColumnMatch) {
|
||||||
targetValue = targetValue.toString().toLowerCase();
|
if (options.onColumnMatch({
|
||||||
if (targetValue.indexOf(searchText) > -1) {
|
searchText,
|
||||||
|
value: targetValue,
|
||||||
|
column,
|
||||||
|
row
|
||||||
|
})) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (targetValue !== null && typeof targetValue !== 'undefined') {
|
||||||
|
targetValue = targetValue.toString().toLowerCase();
|
||||||
|
if (targetValue.indexOf(searchText) > -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
file-saver@1.3.8:
|
file-saver@2.0.2:
|
||||||
version "1.3.8"
|
version "2.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-1.3.8.tgz#e68a30c7cb044e2fb362b428469feb291c2e09d8"
|
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.2.tgz#06d6e728a9ea2df2cce2f8d9e84dfcdc338ec17a"
|
||||||
|
integrity sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw==
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "3.1.1",
|
"version": "3.3.3",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint arrow-body-style: 0 */
|
/* eslint arrow-body-style: 0 */
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
@@ -5,6 +6,7 @@ import PropTypes from 'prop-types';
|
|||||||
import cs from 'classnames';
|
import cs from 'classnames';
|
||||||
|
|
||||||
import Header from './header';
|
import Header from './header';
|
||||||
|
import Filters from './filters';
|
||||||
import Caption from './caption';
|
import Caption from './caption';
|
||||||
import Body from './body';
|
import Body from './body';
|
||||||
import Footer from './footer';
|
import Footer from './footer';
|
||||||
@@ -18,7 +20,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
this.validateProps();
|
this.validateProps();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.onDataSizeChange && !nextProps.pagination) {
|
if (nextProps.onDataSizeChange && !nextProps.pagination) {
|
||||||
if (nextProps.data.length !== this.props.data.length) {
|
if (nextProps.data.length !== this.props.data.length) {
|
||||||
nextProps.onDataSizeChange({ dataSize: nextProps.data.length });
|
nextProps.onDataSizeChange({ dataSize: nextProps.data.length });
|
||||||
@@ -64,7 +66,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
rowEvents,
|
rowEvents,
|
||||||
selectRow,
|
selectRow,
|
||||||
expandRow,
|
expandRow,
|
||||||
cellEdit
|
cellEdit,
|
||||||
|
filterPosition
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses);
|
const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses);
|
||||||
@@ -76,9 +79,13 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
[bootstrap4 ? 'table-sm' : 'table-condensed']: condensed
|
[bootstrap4 ? 'table-sm' : 'table-condensed']: condensed
|
||||||
}, classes);
|
}, classes);
|
||||||
|
|
||||||
|
const hasFilters = columns.some(col => col.filter || col.filterRenderer);
|
||||||
|
|
||||||
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
||||||
|
|
||||||
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
const tableCaption = (
|
||||||
|
caption && <Caption bootstrap4={ bootstrap4 }>{ caption }</Caption>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={ tableWrapperClass }>
|
<div className={ tableWrapperClass }>
|
||||||
@@ -90,11 +97,27 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
sortField={ this.props.sortField }
|
sortField={ this.props.sortField }
|
||||||
sortOrder={ this.props.sortOrder }
|
sortOrder={ this.props.sortOrder }
|
||||||
onSort={ this.props.onSort }
|
onSort={ this.props.onSort }
|
||||||
|
globalSortCaret={ this.props.sort && this.props.sort.sortCaret }
|
||||||
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 }
|
||||||
|
filterPosition={ filterPosition }
|
||||||
/>
|
/>
|
||||||
|
{hasFilters && filterPosition !== Const.FILTERS_POSITION_INLINE && (
|
||||||
|
<Filters
|
||||||
|
columns={ columns }
|
||||||
|
className={ this.props.filtersClasses }
|
||||||
|
onSort={ this.props.onSort }
|
||||||
|
onFilter={ this.props.onFilter }
|
||||||
|
currFilters={ this.props.currFilters }
|
||||||
|
filterPosition={ this.props.filterPosition }
|
||||||
|
onExternalFilter={ this.props.onExternalFilter }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Body
|
<Body
|
||||||
data={ this.getData() }
|
data={ this.getData() }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
@@ -133,7 +156,7 @@ BootstrapTable.propTypes = {
|
|||||||
remote: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
remote: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
||||||
pagination: PropTypes.bool
|
pagination: PropTypes.bool
|
||||||
})]),
|
})]),
|
||||||
noDataIndication: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
noDataIndication: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
||||||
striped: PropTypes.bool,
|
striped: PropTypes.bool,
|
||||||
bordered: PropTypes.bool,
|
bordered: PropTypes.bool,
|
||||||
hover: PropTypes.bool,
|
hover: PropTypes.bool,
|
||||||
@@ -164,10 +187,18 @@ BootstrapTable.propTypes = {
|
|||||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
nonSelectable: PropTypes.array,
|
nonSelectable: PropTypes.array,
|
||||||
|
nonSelectableStyle: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
|
nonSelectableClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
hideSelectColumn: PropTypes.bool,
|
hideSelectColumn: PropTypes.bool,
|
||||||
selectionRenderer: PropTypes.func,
|
selectionRenderer: PropTypes.func,
|
||||||
selectionHeaderRenderer: PropTypes.func
|
selectionHeaderRenderer: PropTypes.func,
|
||||||
|
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
|
selectColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
|
selectColumnPosition: PropTypes.oneOf([
|
||||||
|
Const.INDICATOR_POSITION_LEFT,
|
||||||
|
Const.INDICATOR_POSITION_RIGHT
|
||||||
|
])
|
||||||
}),
|
}),
|
||||||
expandRow: PropTypes.shape({
|
expandRow: PropTypes.shape({
|
||||||
renderer: PropTypes.func,
|
renderer: PropTypes.func,
|
||||||
@@ -183,17 +214,31 @@ BootstrapTable.propTypes = {
|
|||||||
expandColumnPosition: PropTypes.oneOf([
|
expandColumnPosition: PropTypes.oneOf([
|
||||||
Const.INDICATOR_POSITION_LEFT,
|
Const.INDICATOR_POSITION_LEFT,
|
||||||
Const.INDICATOR_POSITION_RIGHT
|
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]),
|
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
rowEvents: PropTypes.object,
|
rowEvents: PropTypes.object,
|
||||||
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
headerClasses: PropTypes.string,
|
headerClasses: PropTypes.string,
|
||||||
|
filtersClasses: PropTypes.string,
|
||||||
|
filterPosition: PropTypes.oneOf([
|
||||||
|
Const.FILTERS_POSITION_TOP,
|
||||||
|
Const.FILTERS_POSITION_INLINE,
|
||||||
|
Const.FILTERS_POSITION_BOTTOM
|
||||||
|
]),
|
||||||
footerClasses: PropTypes.string,
|
footerClasses: PropTypes.string,
|
||||||
defaultSorted: PropTypes.arrayOf(PropTypes.shape({
|
defaultSorted: PropTypes.arrayOf(PropTypes.shape({
|
||||||
dataField: PropTypes.string.isRequired,
|
dataField: PropTypes.string.isRequired,
|
||||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
||||||
})),
|
})),
|
||||||
|
sort: PropTypes.shape({
|
||||||
|
dataField: PropTypes.string,
|
||||||
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||||
|
sortFunc: PropTypes.func,
|
||||||
|
sortCaret: PropTypes.func
|
||||||
|
}),
|
||||||
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||||
overlay: PropTypes.func,
|
overlay: PropTypes.func,
|
||||||
onTableChange: PropTypes.func,
|
onTableChange: PropTypes.func,
|
||||||
@@ -230,7 +275,8 @@ BootstrapTable.defaultProps = {
|
|||||||
cellEdit: {
|
cellEdit: {
|
||||||
mode: null,
|
mode: null,
|
||||||
nonEditableRows: []
|
nonEditableRows: []
|
||||||
}
|
},
|
||||||
|
filterPosition: Const.FILTERS_POSITION_INLINE
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BootstrapTable;
|
export default BootstrapTable;
|
||||||
|
|||||||
12
packages/react-bootstrap-table2/src/caption.js
vendored
12
packages/react-bootstrap-table2/src/caption.js
vendored
@@ -4,16 +4,22 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
const Caption = (props) => {
|
const Caption = (props) => {
|
||||||
if (!props.children) return null;
|
if (!props.children) return null;
|
||||||
return (
|
|
||||||
<caption>{ props.children }</caption>
|
const caption = props.bootstrap4 ? (
|
||||||
|
<caption style={ { captionSide: 'top' } }>{props.children}</caption>
|
||||||
|
) : (
|
||||||
|
<caption>{props.children}</caption>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return caption;
|
||||||
};
|
};
|
||||||
|
|
||||||
Caption.propTypes = {
|
Caption.propTypes = {
|
||||||
children: PropTypes.oneOfType([
|
children: PropTypes.oneOfType([
|
||||||
PropTypes.node,
|
PropTypes.node,
|
||||||
PropTypes.string
|
PropTypes.string
|
||||||
])
|
]),
|
||||||
|
bootstrap4: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Caption;
|
export default Caption;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import _ from './utils';
|
||||||
|
|
||||||
const events = [
|
const events = [
|
||||||
'onClick',
|
'onClick',
|
||||||
'onDoubleClick',
|
'onDoubleClick',
|
||||||
@@ -15,15 +17,15 @@ export default ExtendBase =>
|
|||||||
|
|
||||||
createDefaultEventHandler(cb) {
|
createDefaultEventHandler(cb) {
|
||||||
return (e) => {
|
return (e) => {
|
||||||
const { column, columnIndex } = this.props;
|
const { column, columnIndex, index } = this.props;
|
||||||
cb(e, column, columnIndex);
|
cb(e, column, typeof columnIndex !== 'undefined' ? columnIndex : index);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate(attrs = {}) {
|
delegate(attrs = {}) {
|
||||||
const newAttrs = { ...attrs };
|
const newAttrs = { ...attrs };
|
||||||
Object.keys(attrs).forEach((attr) => {
|
Object.keys(attrs).forEach((attr) => {
|
||||||
if (events.includes(attr)) {
|
if (_.contains(events, attr)) {
|
||||||
newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]);
|
newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
22
packages/react-bootstrap-table2/src/cell.js
vendored
22
packages/react-bootstrap-table2/src/cell.js
vendored
@@ -8,7 +8,7 @@ import _ from './utils';
|
|||||||
class Cell extends eventDelegater(Component) {
|
class Cell extends eventDelegater(Component) {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.handleEditingCell = this.handleEditingCell.bind(this);
|
this.createHandleEditingCell = this.createHandleEditingCell.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
@@ -28,6 +28,7 @@ class Cell extends eventDelegater(Component) {
|
|||||||
shouldUpdate =
|
shouldUpdate =
|
||||||
(nextProps.column.formatter ? !_.isEqual(this.props.row, nextProps.row) : false) ||
|
(nextProps.column.formatter ? !_.isEqual(this.props.row, nextProps.row) : false) ||
|
||||||
this.props.column.hidden !== nextProps.column.hidden ||
|
this.props.column.hidden !== nextProps.column.hidden ||
|
||||||
|
this.props.column.isDummyField !== nextProps.column.isDummyField ||
|
||||||
this.props.rowIndex !== nextProps.rowIndex ||
|
this.props.rowIndex !== nextProps.rowIndex ||
|
||||||
this.props.columnIndex !== nextProps.columnIndex ||
|
this.props.columnIndex !== nextProps.columnIndex ||
|
||||||
this.props.className !== nextProps.className ||
|
this.props.className !== nextProps.className ||
|
||||||
@@ -43,17 +44,10 @@ class Cell extends eventDelegater(Component) {
|
|||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEditingCell(e) {
|
createHandleEditingCell = originFunc => (e) => {
|
||||||
const { column, onStart, rowIndex, columnIndex, clickToEdit, dbclickToEdit } = this.props;
|
const { onStart, rowIndex, columnIndex, clickToEdit, dbclickToEdit } = this.props;
|
||||||
const { events } = column;
|
if ((clickToEdit || dbclickToEdit) && _.isFunction(originFunc)) {
|
||||||
if (events) {
|
originFunc(e);
|
||||||
if (clickToEdit) {
|
|
||||||
const customClick = events.onClick;
|
|
||||||
if (_.isFunction(customClick)) customClick(e);
|
|
||||||
} else if (dbclickToEdit) {
|
|
||||||
const customDbClick = events.onDoubleClick;
|
|
||||||
if (_.isFunction(customDbClick)) customDbClick(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (onStart) {
|
if (onStart) {
|
||||||
onStart(rowIndex, columnIndex);
|
onStart(rowIndex, columnIndex);
|
||||||
@@ -85,9 +79,9 @@ class Cell extends eventDelegater(Component) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (clickToEdit && editable) {
|
if (clickToEdit && editable) {
|
||||||
attrs.onClick = this.handleEditingCell;
|
attrs.onClick = this.createHandleEditingCell(attrs.onClick);
|
||||||
} else if (dbclickToEdit && editable) {
|
} else if (dbclickToEdit && editable) {
|
||||||
attrs.onDoubleClick = this.handleEditingCell;
|
attrs.onDoubleClick = this.createHandleEditingCell(attrs.onDoubleClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
9
packages/react-bootstrap-table2/src/const.js
vendored
9
packages/react-bootstrap-table2/src/const.js
vendored
@@ -8,5 +8,12 @@ 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',
|
||||||
|
FILTERS_POSITION_INLINE: 'inline',
|
||||||
|
FILTERS_POSITION_TOP: 'top',
|
||||||
|
FILTERS_POSITION_BOTTOM: 'bottom'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
@@ -12,10 +13,6 @@ export default () => {
|
|||||||
|
|
||||||
state = { data: this.props.data };
|
state = { data: this.props.data };
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
this.setState(() => ({ data: nextProps.data }));
|
|
||||||
}
|
|
||||||
|
|
||||||
getData = (filterProps, searchProps, sortProps, paginationProps) => {
|
getData = (filterProps, searchProps, sortProps, paginationProps) => {
|
||||||
if (paginationProps) return paginationProps.data;
|
if (paginationProps) return paginationProps.data;
|
||||||
else if (sortProps) return sortProps.data;
|
else if (sortProps) return sortProps.data;
|
||||||
@@ -24,6 +21,10 @@ export default () => {
|
|||||||
return this.props.data;
|
return this.props.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
this.setState(() => ({ data: nextProps.data }));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<DataContext.Provider
|
<DataContext.Provider
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
/* eslint no-param-reassign: 0 */
|
/* eslint no-param-reassign: 0 */
|
||||||
/* eslint class-methods-use-this: 0 */
|
/* eslint class-methods-use-this: 0 */
|
||||||
@@ -83,7 +84,7 @@ const withContext = Base =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
if (!nextProps.pagination && this.props.pagination) {
|
if (!nextProps.pagination && this.props.pagination) {
|
||||||
this.PaginationContext = null;
|
this.PaginationContext = null;
|
||||||
}
|
}
|
||||||
@@ -91,6 +92,13 @@ const withContext = Base =>
|
|||||||
this.PaginationContext = nextProps.pagination.createContext(
|
this.PaginationContext = nextProps.pagination.createContext(
|
||||||
this.isRemotePagination, this.handleRemotePageChange);
|
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() {
|
renderBase() {
|
||||||
@@ -239,6 +247,7 @@ const withContext = Base =>
|
|||||||
ref={ n => this.sortContext = n }
|
ref={ n => this.sortContext = n }
|
||||||
defaultSorted={ this.props.defaultSorted }
|
defaultSorted={ this.props.defaultSorted }
|
||||||
defaultSortDirection={ this.props.defaultSortDirection }
|
defaultSortDirection={ this.props.defaultSortDirection }
|
||||||
|
sort={ this.props.sort }
|
||||||
data={ rootProps.getData(filterProps, searchProps) }
|
data={ rootProps.getData(filterProps, searchProps) }
|
||||||
>
|
>
|
||||||
<this.SortContext.Consumer>
|
<this.SortContext.Consumer>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import dataOperator from '../store/operators';
|
import dataOperator from '../store/operators';
|
||||||
|
import _ from '../utils';
|
||||||
|
|
||||||
const RowExpandContext = React.createContext();
|
const RowExpandContext = React.createContext();
|
||||||
|
|
||||||
@@ -15,11 +17,15 @@ class RowExpandProvider extends React.Component {
|
|||||||
state = { expanded: this.props.expandRow.expanded || [],
|
state = { expanded: this.props.expandRow.expanded || [],
|
||||||
isClosing: this.props.expandRow.isClosing || [] };
|
isClosing: this.props.expandRow.isClosing || [] };
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
onClosed = (closedRow) => {
|
||||||
|
this.setState({ isClosing: this.state.isClosing.filter(value => value !== closedRow) });
|
||||||
|
};
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.expandRow) {
|
if (nextProps.expandRow) {
|
||||||
const nextExpanded = nextProps.expandRow.expanded || this.state.expanded;
|
const nextExpanded = nextProps.expandRow.expanded || this.state.expanded;
|
||||||
const isClosing = this.state.expanded.reduce((acc, cur) => {
|
const isClosing = this.state.expanded.reduce((acc, cur) => {
|
||||||
if (!nextExpanded.includes(cur)) {
|
if (!_.contains(nextExpanded, cur)) {
|
||||||
acc.push(cur);
|
acc.push(cur);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
@@ -35,13 +41,9 @@ class RowExpandProvider extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onClosed = (closedRow) => {
|
|
||||||
this.setState({ isClosing: this.state.isClosing.filter(value => value !== closedRow) });
|
|
||||||
};
|
|
||||||
|
|
||||||
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
||||||
const { data, keyField, expandRow: { onExpand, onlyOneExpanding, nonExpandable } } = this.props;
|
const { data, keyField, expandRow: { onExpand, onlyOneExpanding, nonExpandable } } = this.props;
|
||||||
if (nonExpandable && nonExpandable.includes(rowKey)) {
|
if (nonExpandable && _.contains(nonExpandable, rowKey)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ class RowExpandProvider extends React.Component {
|
|||||||
if (expandAll) {
|
if (expandAll) {
|
||||||
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
|
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
|
||||||
} else {
|
} else {
|
||||||
currExpanded = expanded.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
currExpanded = expanded.filter(s => typeof data.find(d => _.get(d, keyField) === s) === 'undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onExpandAll) {
|
if (onExpandAll) {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Const from '../const';
|
import Const from '../const';
|
||||||
|
import _ from '../utils';
|
||||||
|
|
||||||
import dataOperator from '../store/operators';
|
import dataOperator from '../store/operators';
|
||||||
import { getSelectionSummary } from '../store/selection';
|
import { getSelectionSummary } from '../store/selection';
|
||||||
@@ -19,17 +21,17 @@ class SelectionProvider extends React.Component {
|
|||||||
this.selected = props.selectRow.selected || [];
|
this.selected = props.selectRow.selected || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
if (nextProps.selectRow) {
|
|
||||||
this.selected = nextProps.selectRow.selected || this.selected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// exposed API
|
// exposed API
|
||||||
getSelected() {
|
getSelected() {
|
||||||
return this.selected;
|
return this.selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
if (nextProps.selectRow) {
|
||||||
|
this.selected = nextProps.selectRow.selected || this.selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleRowSelect = (rowKey, checked, rowIndex, e) => {
|
handleRowSelect = (rowKey, checked, rowIndex, e) => {
|
||||||
const { data, keyField, selectRow: { mode, onSelect } } = this.props;
|
const { data, keyField, selectRow: { mode, onSelect } } = this.props;
|
||||||
const { ROW_SELECT_SINGLE } = Const;
|
const { ROW_SELECT_SINGLE } = Const;
|
||||||
@@ -71,7 +73,7 @@ class SelectionProvider extends React.Component {
|
|||||||
if (!isUnSelect) {
|
if (!isUnSelect) {
|
||||||
currSelected = selected.concat(dataOperator.selectableKeys(data, keyField, nonSelectable));
|
currSelected = selected.concat(dataOperator.selectableKeys(data, keyField, nonSelectable));
|
||||||
} else {
|
} else {
|
||||||
currSelected = selected.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
currSelected = selected.filter(s => typeof data.find(d => _.get(d, keyField) === s) === 'undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
@@ -19,6 +20,11 @@ export default (
|
|||||||
dataField: PropTypes.string.isRequired,
|
dataField: PropTypes.string.isRequired,
|
||||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
||||||
})),
|
})),
|
||||||
|
sort: PropTypes.shape({
|
||||||
|
dataField: PropTypes.string,
|
||||||
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||||
|
sortFunc: PropTypes.func
|
||||||
|
}),
|
||||||
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC])
|
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,19 +32,14 @@ export default (
|
|||||||
super(props);
|
super(props);
|
||||||
let sortOrder;
|
let sortOrder;
|
||||||
let sortColumn;
|
let sortColumn;
|
||||||
const { columns, defaultSorted, defaultSortDirection } = props;
|
const { defaultSorted, defaultSortDirection, sort } = props;
|
||||||
|
|
||||||
if (defaultSorted && defaultSorted.length > 0) {
|
if (defaultSorted && defaultSorted.length > 0) {
|
||||||
const sortField = defaultSorted[0].dataField;
|
|
||||||
sortOrder = defaultSorted[0].order || defaultSortDirection;
|
sortOrder = defaultSorted[0].order || defaultSortDirection;
|
||||||
const sortColumns = columns.filter(col => col.dataField === sortField);
|
sortColumn = this.initSort(defaultSorted[0].dataField, sortOrder);
|
||||||
if (sortColumns.length > 0) {
|
} else if (sort && sort.dataField && sort.order) {
|
||||||
sortColumn = sortColumns[0];
|
sortOrder = sort.order;
|
||||||
|
sortColumn = this.initSort(sort.dataField, sortOrder);
|
||||||
if (sortColumn.onSort) {
|
|
||||||
sortColumn.onSort(sortField, sortOrder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.state = { sortOrder, sortColumn };
|
this.state = { sortOrder, sortColumn };
|
||||||
}
|
}
|
||||||
@@ -50,6 +51,30 @@ export default (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
const { sort, columns } = nextProps;
|
||||||
|
if (sort && sort.dataField && sort.order) {
|
||||||
|
this.setState({
|
||||||
|
sortOrder: sort.order,
|
||||||
|
sortColumn: columns.find(col => col.dataField === sort.dataField)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initSort(sortField, sortOrder) {
|
||||||
|
let sortColumn;
|
||||||
|
const { columns } = this.props;
|
||||||
|
const sortColumns = columns.filter(col => col.dataField === sortField);
|
||||||
|
if (sortColumns.length > 0) {
|
||||||
|
sortColumn = sortColumns[0];
|
||||||
|
|
||||||
|
if (sortColumn.onSort) {
|
||||||
|
sortColumn.onSort(sortField, sortOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sortColumn;
|
||||||
|
}
|
||||||
|
|
||||||
handleSort = (column) => {
|
handleSort = (column) => {
|
||||||
const sortOrder = dataOperator.nextOrder(column, this.state, this.props.defaultSortDirection);
|
const sortOrder = dataOperator.nextOrder(column, this.state, this.props.defaultSortDirection);
|
||||||
|
|
||||||
@@ -68,9 +93,11 @@ export default (
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { data } = this.props;
|
let { data } = this.props;
|
||||||
|
const { sort } = this.props;
|
||||||
const { sortOrder, sortColumn } = this.state;
|
const { sortOrder, sortColumn } = this.state;
|
||||||
if (!isRemoteSort() && sortColumn) {
|
if (!isRemoteSort() && sortColumn) {
|
||||||
data = dataOperator.sort(data, sortOrder, sortColumn);
|
const sortFunc = sortColumn.sortFunc ? sortColumn.sortFunc : (sort && sort.sortFunc);
|
||||||
|
data = dataOperator.sort(data, sortOrder, { ...sortColumn, sortFunc });
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
49
packages/react-bootstrap-table2/src/filters-cell.js
vendored
Normal file
49
packages/react-bootstrap-table2/src/filters-cell.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import _ from './utils';
|
||||||
|
|
||||||
|
const FiltersCell = (props) => {
|
||||||
|
const {
|
||||||
|
index, column, onExternalFilter,
|
||||||
|
currFilters, onFilter
|
||||||
|
} = props;
|
||||||
|
const { filterRenderer, filter } = column;
|
||||||
|
let filterElm;
|
||||||
|
const cellAttrs = {};
|
||||||
|
const cellStyle = {};
|
||||||
|
cellAttrs.style = cellStyle;
|
||||||
|
if (column.headerAlign) {
|
||||||
|
cellStyle.textAlign = _.isFunction(column.headerAlign)
|
||||||
|
? column.headerAlign(column, index)
|
||||||
|
: column.headerAlign;
|
||||||
|
}
|
||||||
|
if (column.filterRenderer) {
|
||||||
|
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||||
|
filterElm = filterRenderer(onCustomFilter, column);
|
||||||
|
} else if (filter) {
|
||||||
|
filterElm = (
|
||||||
|
<filter.Filter
|
||||||
|
{ ...filter.props }
|
||||||
|
filterState={ currFilters[column.dataField] }
|
||||||
|
onFilter={ onFilter }
|
||||||
|
column={ column }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return React.createElement('th', cellAttrs, filterElm);
|
||||||
|
};
|
||||||
|
|
||||||
|
FiltersCell.propTypes = {
|
||||||
|
index: PropTypes.number.isRequired,
|
||||||
|
column: PropTypes.object.isRequired,
|
||||||
|
currFilters: PropTypes.object.isRequired,
|
||||||
|
onFilter: PropTypes.func,
|
||||||
|
onExternalFilter: PropTypes.func
|
||||||
|
};
|
||||||
|
|
||||||
|
FiltersCell.defaultProps = {
|
||||||
|
onFilter: () => { },
|
||||||
|
onExternalFilter: () => { }
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FiltersCell;
|
||||||
83
packages/react-bootstrap-table2/src/filters.js
vendored
Normal file
83
packages/react-bootstrap-table2/src/filters.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/* eslint react/require-default-props: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import FiltersCell from './filters-cell';
|
||||||
|
import Const from './const';
|
||||||
|
import RowTemplate from './row/row-template';
|
||||||
|
|
||||||
|
const Filters = (props) => {
|
||||||
|
const {
|
||||||
|
columns,
|
||||||
|
onFilter,
|
||||||
|
currFilters,
|
||||||
|
filterPosition,
|
||||||
|
onExternalFilter,
|
||||||
|
className,
|
||||||
|
selectRow,
|
||||||
|
expandRow
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
function renderContent() {
|
||||||
|
const filterColumns = [];
|
||||||
|
let showFiltersRow = false;
|
||||||
|
|
||||||
|
columns.forEach((column, i) => {
|
||||||
|
filterColumns.push(<FiltersCell
|
||||||
|
index={ i }
|
||||||
|
key={ column.dataField }
|
||||||
|
column={ column }
|
||||||
|
currFilters={ currFilters }
|
||||||
|
onExternalFilter={ onExternalFilter }
|
||||||
|
onFilter={ onFilter }
|
||||||
|
/>);
|
||||||
|
|
||||||
|
if (column.filterRenderer || column.filter) {
|
||||||
|
if (!showFiltersRow) {
|
||||||
|
showFiltersRow = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return filterColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tbody
|
||||||
|
className={ className }
|
||||||
|
style={ {
|
||||||
|
display:
|
||||||
|
filterPosition === Const.FILTERS_POSITION_TOP
|
||||||
|
? 'table-header-group'
|
||||||
|
: 'table-footer-group'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
<RowTemplate
|
||||||
|
renderContent={ renderContent }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
cellEl="td"
|
||||||
|
/>
|
||||||
|
</tbody>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Filters.propTypes = {
|
||||||
|
columns: PropTypes.array.isRequired,
|
||||||
|
onFilter: PropTypes.func,
|
||||||
|
filterPosition: PropTypes.oneOf([
|
||||||
|
Const.FILTERS_POSITION_TOP,
|
||||||
|
Const.FILTERS_POSITION_INLINE,
|
||||||
|
Const.FILTERS_POSITION_BOTTOM
|
||||||
|
]),
|
||||||
|
currFilters: PropTypes.object,
|
||||||
|
onExternalFilter: PropTypes.func,
|
||||||
|
className: PropTypes.string,
|
||||||
|
selectRow: PropTypes.object,
|
||||||
|
expandRow: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
|
Filters.defaultProps = {
|
||||||
|
position: Const.FILTERS_POSITION_TOP
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Filters;
|
||||||
@@ -4,56 +4,61 @@ import cs from 'classnames';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
|
import eventDelegater from './cell-event-delegater';
|
||||||
|
|
||||||
const FooterCell = (props) => {
|
class FooterCell extends eventDelegater(React.Component) {
|
||||||
const { index, column, columnData } = props;
|
render() {
|
||||||
|
const { index, column, columnData } = this.props;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
footer,
|
footer,
|
||||||
footerTitle,
|
footerTitle,
|
||||||
footerAlign,
|
footerAlign,
|
||||||
footerFormatter,
|
footerFormatter,
|
||||||
footerEvents,
|
footerEvents,
|
||||||
footerClasses,
|
footerClasses,
|
||||||
footerStyle,
|
footerStyle,
|
||||||
footerAttrs
|
footerAttrs
|
||||||
} = column;
|
} = column;
|
||||||
|
|
||||||
const cellAttrs = {
|
const delegateEvents = this.delegate(footerEvents);
|
||||||
...(_.isFunction(footerAttrs) ? footerAttrs(column, index) : footerAttrs),
|
const cellAttrs = {
|
||||||
...footerEvents
|
...(_.isFunction(footerAttrs) ? footerAttrs(column, index) : footerAttrs),
|
||||||
};
|
...delegateEvents
|
||||||
|
};
|
||||||
|
|
||||||
let text = '';
|
|
||||||
if (_.isString(footer)) {
|
let text = '';
|
||||||
text = footer;
|
if (_.isString(footer)) {
|
||||||
} else if (_.isFunction(footer)) {
|
text = footer;
|
||||||
text = footer(columnData, column, index);
|
} else if (_.isFunction(footer)) {
|
||||||
|
text = footer(columnData, column, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cellStyle = {};
|
||||||
|
const cellClasses = _.isFunction(footerClasses) ? footerClasses(column, index) : footerClasses;
|
||||||
|
|
||||||
|
if (footerStyle) {
|
||||||
|
cellStyle = _.isFunction(footerStyle) ? footerStyle(column, index) : footerStyle;
|
||||||
|
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (footerTitle) {
|
||||||
|
cellAttrs.title = _.isFunction(footerTitle) ? footerTitle(column, index) : text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (footerAlign) {
|
||||||
|
cellStyle.textAlign = _.isFunction(footerAlign) ? footerAlign(column, index) : footerAlign;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
|
||||||
|
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
||||||
|
|
||||||
|
const children = footerFormatter ? footerFormatter(column, index) : text;
|
||||||
|
|
||||||
|
return React.createElement('th', cellAttrs, children);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let cellStyle = {};
|
|
||||||
const cellClasses = _.isFunction(footerClasses) ? footerClasses(column, index) : footerClasses;
|
|
||||||
|
|
||||||
if (footerStyle) {
|
|
||||||
cellStyle = _.isFunction(footerStyle) ? footerStyle(column, index) : footerStyle;
|
|
||||||
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (footerTitle) {
|
|
||||||
cellAttrs.title = _.isFunction(footerTitle) ? footerTitle(column, index) : text;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (footerAlign) {
|
|
||||||
cellStyle.textAlign = _.isFunction(footerAlign) ? footerAlign(column, index) : footerAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
|
|
||||||
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
|
||||||
|
|
||||||
const children = footerFormatter ? footerFormatter(column, index) : text;
|
|
||||||
|
|
||||||
return React.createElement('th', cellAttrs, children);
|
|
||||||
};
|
|
||||||
|
|
||||||
FooterCell.propTypes = {
|
FooterCell.propTypes = {
|
||||||
columnData: PropTypes.array,
|
columnData: PropTypes.array,
|
||||||
|
|||||||
58
packages/react-bootstrap-table2/src/footer.js
vendored
58
packages/react-bootstrap-table2/src/footer.js
vendored
@@ -2,53 +2,41 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import Const from './const';
|
import RowTemplate from './row/row-template';
|
||||||
import FooterCell from './footer-cell';
|
import FooterCell from './footer-cell';
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
|
|
||||||
const Footer = (props) => {
|
const Footer = (props) => {
|
||||||
const { data, className, columns, selectRow, expandRow } = props;
|
const { data, className, columns, selectRow, expandRow } = props;
|
||||||
const SelectionFooterCellComp = () => <th />;
|
|
||||||
const ExpansionFooterCellComp = () => <th />;
|
|
||||||
|
|
||||||
const isRenderExpandColumnInLeft = (
|
function renderContent() {
|
||||||
expandColumnPosition = Const.INDICATOR_POSITION_LEFT
|
return columns.map((column, i) => {
|
||||||
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT;
|
if (column.footer === undefined || column.footer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const childrens = columns.map((column, i) => {
|
const columnData = _.pluck(data, column.dataField);
|
||||||
if (column.footer === undefined || column.footer === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const columnData = _.pluck(data, column.dataField);
|
return (
|
||||||
|
<FooterCell
|
||||||
return (
|
index={ i }
|
||||||
<FooterCell
|
key={ column.dataField }
|
||||||
index={ i }
|
column={ column }
|
||||||
key={ column.dataField }
|
columnData={ columnData }
|
||||||
column={ column }
|
/>
|
||||||
columnData={ columnData }
|
);
|
||||||
/>
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (selectRow && selectRow.hideSelectColumn !== true) {
|
|
||||||
childrens.unshift(<SelectionFooterCellComp key="selection" />);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expandRow.showExpandColumn) {
|
|
||||||
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) {
|
|
||||||
childrens.unshift(<ExpansionFooterCellComp key="expansion" />);
|
|
||||||
} else {
|
|
||||||
childrens.push(<ExpansionFooterCellComp key="expansion" />);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr className={ className }>
|
<RowTemplate
|
||||||
{ childrens }
|
renderContent={ renderContent }
|
||||||
</tr>
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
className={ className }
|
||||||
|
cellEl="th"
|
||||||
|
/>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user