mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 13:40:07 +00:00
Compare commits
227 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 | ||
|
|
e2e6c51d40 | ||
|
|
fb724331d3 | ||
|
|
160dede412 | ||
|
|
363a43251f | ||
|
|
8ad0e65679 | ||
|
|
6d5cca0047 | ||
|
|
204e75c9c2 | ||
|
|
fc27c56cbb | ||
|
|
8436edba7e | ||
|
|
3606fa3b7b | ||
|
|
73e8701bde | ||
|
|
6d2493d537 | ||
|
|
1a1f6969cb | ||
|
|
d47a3757b8 | ||
|
|
ba7512969e | ||
|
|
955ee17939 | ||
|
|
497bf44192 | ||
|
|
fcefcf8c84 | ||
|
|
04e3af0bbb | ||
|
|
9f47fa009c | ||
|
|
0edf9c8891 | ||
|
|
df5024892c | ||
|
|
4448c3f28c | ||
|
|
196ae33295 | ||
|
|
7f1b7a6c97 | ||
|
|
a6ccafcc75 | ||
|
|
06d87299a3 | ||
|
|
5891ec1b93 | ||
|
|
c5d9e04c2c | ||
|
|
dba3da28c1 | ||
|
|
a0e09cd804 | ||
|
|
d0e70f7246 | ||
|
|
b93c683f17 | ||
|
|
f80e1ea66c | ||
|
|
7642bfa1a3 | ||
|
|
8f304a849f | ||
|
|
956f1cef4d | ||
|
|
c45deee590 | ||
|
|
2aab4301dd | ||
|
|
43aa280761 | ||
|
|
3af30a0265 | ||
|
|
4b8b8b261e | ||
|
|
e44782f222 | ||
|
|
921e8c7ecc | ||
|
|
a3b3ce0dc4 | ||
|
|
e9f08d278d | ||
|
|
b4973c826c | ||
|
|
33c026c7e2 | ||
|
|
6cac7f6dc8 | ||
|
|
da5b93c3cf | ||
|
|
3ffccce1fe | ||
|
|
09f21e8130 | ||
|
|
bf0c5c43a2 | ||
|
|
c01f45a719 | ||
|
|
d26c13b9be | ||
|
|
d84fd5c801 | ||
|
|
8e940112f5 | ||
|
|
6070d150a9 | ||
|
|
dab6f1b206 | ||
|
|
2a497194e7 | ||
|
|
f5f17897fd | ||
|
|
2932b8a1b8 | ||
|
|
93103e5ca0 | ||
|
|
a7c2a49182 | ||
|
|
cd27ff98ff | ||
|
|
4d815894e6 | ||
|
|
d9ff201373 | ||
|
|
8e142de332 | ||
|
|
322605f14e | ||
|
|
3156e01dd6 | ||
|
|
052284a163 | ||
|
|
3cd8efffb9 | ||
|
|
447d69cae5 | ||
|
|
cacc28e1bc | ||
|
|
d7f84a9da5 | ||
|
|
63c2630f46 | ||
|
|
903dd2e5c8 | ||
|
|
964faa53e3 | ||
|
|
8fb5364cc2 | ||
|
|
8b89b3de0e | ||
|
|
4506a3dea2 | ||
|
|
ecea3efdaa | ||
|
|
8bef7eb348 | ||
|
|
408a004f58 | ||
|
|
bf46dfa026 | ||
|
|
f1b39e3dd6 | ||
|
|
029cd3ab6f | ||
|
|
1c68892a7b | ||
|
|
1bf3fa50db | ||
|
|
9988e790c1 | ||
|
|
bb071c98f9 | ||
|
|
9c5d8aac62 | ||
|
|
7c79b64985 | ||
|
|
16f89989f0 | ||
|
|
58cfdacfd1 | ||
|
|
78d5164056 | ||
|
|
bd2ce5abf0 | ||
|
|
416fcf08d4 | ||
|
|
0c650c0682 | ||
|
|
7d30804da9 | ||
|
|
782c630e58 | ||
|
|
22cc79961f | ||
|
|
a83b3d0d78 | ||
|
|
340ddb8722 | ||
|
|
32e455e65f |
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,11 +28,14 @@
|
|||||||
* [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)
|
||||||
|
|
||||||
### <a name='keyField'>keyField(**required**) - [String]</a>
|
### <a name='keyField'>keyField(**required**) - [String]</a>
|
||||||
Tells `react-bootstrap-table2` which column is unique.
|
Tells `react-bootstrap-table2` which column is unique.
|
||||||
@@ -97,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>
|
||||||
@@ -190,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.
|
||||||
|
|
||||||
@@ -200,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`.
|
||||||
|
|
||||||
@@ -318,3 +351,22 @@ 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>
|
||||||
|
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:
|
||||||
|
|
||||||
|
* `dataSize`: The new data size
|
||||||
|
|
||||||
|
```js
|
||||||
|
handleDataChange = ({ dataSize }) => {
|
||||||
|
this.setState({ rowCount: dataSize });
|
||||||
|
}
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
onDataSizeChange={ handleDataChange }
|
||||||
|
....
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const cellEdit: {
|
|||||||
// omit...
|
// omit...
|
||||||
beforeSaveCell(oldValue, newValue, row, column, done) {
|
beforeSaveCell(oldValue, newValue, row, column, done) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (confirm('Do you want to accep this change?')) {
|
if (confirm('Do you want to accept this change?')) {
|
||||||
done(); // contine to save the changes
|
done(); // contine to save the changes
|
||||||
} else {
|
} else {
|
||||||
done(false); // reject the changes
|
done(false); // reject the changes
|
||||||
|
|||||||
216
docs/columns.md
216
docs/columns.md
@@ -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)
|
||||||
@@ -30,6 +32,14 @@ Available properties in a column object:
|
|||||||
* [headerAttrs](#headerAttrs)
|
* [headerAttrs](#headerAttrs)
|
||||||
* [headerSortingClasses](#headerSortingClasses)
|
* [headerSortingClasses](#headerSortingClasses)
|
||||||
* [headerSortingStyle](#headerSortingStyle)
|
* [headerSortingStyle](#headerSortingStyle)
|
||||||
|
* [footer](#footer)
|
||||||
|
* [footerFormatter](#footerFormatter)
|
||||||
|
* [footerClasses](#footerClasses)
|
||||||
|
* [footerStyle](#footerStyle)
|
||||||
|
* [footerTitle](#footerTitle)
|
||||||
|
* [footerEvents](#footerEvents)
|
||||||
|
* [footerAlign](#footerAlign)
|
||||||
|
* [footerAttrs](#footerAttrs)
|
||||||
* [editable](#editable)
|
* [editable](#editable)
|
||||||
* [validator](#validator)
|
* [validator](#validator)
|
||||||
* [editCellStyle](#editCellStyle)
|
* [editCellStyle](#editCellStyle)
|
||||||
@@ -40,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)
|
||||||
@@ -124,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
|
||||||
{
|
{
|
||||||
@@ -156,7 +205,7 @@ Enable the column sort via a `true` value given.
|
|||||||
```
|
```
|
||||||
|
|
||||||
## <a name='sortCaret'>column.sortCaret - [Function]</a>
|
## <a name='sortCaret'>column.sortCaret - [Function]</a>
|
||||||
Use`column.sortCaret` to custom the sort caret. This callback function accept two arguments: `order` and `column`
|
Use`column.sortCaret` to customize the sort caret. This callback function accept two arguments: `order` and `column`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -302,7 +351,7 @@ A new `Object` will be the result of element headerStyle.
|
|||||||
A new `String` will be the result of element title.
|
A new `String` will be the result of element title.
|
||||||
|
|
||||||
## <a name='headerTitle'>column.headerTitle - [Bool | Function]</a>
|
## <a name='headerTitle'>column.headerTitle - [Bool | Function]</a>
|
||||||
`headerTitle` is only for the title on header column, default is disable. The usage almost same as [`column.title`](#title),
|
Configure the title on header column, default is disable. The usage almost same as [`column.title`](#title),
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@@ -407,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) => { ... }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -518,6 +567,162 @@ const sortingHeaderStyle = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='footer'>footer - [String | Function]</a>
|
||||||
|
Give a string to render the string value on the footer column.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footerAlign: 'center',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, .....];
|
||||||
|
```
|
||||||
|
|
||||||
|
This prop also accept a function:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: column => column.reduce((acc, item) => acc + item, 0)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## <a name='footerFormatter'>column.footerFormatter - [Function]</a>
|
||||||
|
`footerFormatter` allow you to customize the table footer column and only accept a callback function which take two arguments and a JSX/String are expected for return.
|
||||||
|
|
||||||
|
* `column`
|
||||||
|
* `columnIndex`
|
||||||
|
|
||||||
|
## <a name='footerClasses'>column.footerClasses - [String | Function]</a>
|
||||||
|
It's similar to [`column.classes`](#classes), `footerClasses` is available to have customized class on table footer column:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerClasses: 'id-custom-cell'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Furthermore, it also accept a callback function which takes 2 arguments and a `String` is expect to return:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
footerClasses: function callback(column, colIndex) { ... }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
* `column`: The value of current column.
|
||||||
|
* `colIndex`: The index of the current `column` being processed in `BootstrapTable`.
|
||||||
|
|
||||||
|
## <a name='footerStyle'>column.footerStyle - [Object | Function]</a>
|
||||||
|
Customized the inline-style on table footer column:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerStyle: { backgroundColor: 'green' }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Moreover, it also accept a callback function which takes **2** arguments and an `Object` is expect to return:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
footerStyle: function callback(column, colIndex) { ... }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
* `column`: The value of current column.
|
||||||
|
* `colIndex`: The index of the current `column` being processed in `BootstrapTable`.
|
||||||
|
|
||||||
|
## <a name='footerTitle'>column.footerTitle - [Bool | Function]</a>
|
||||||
|
Configure the title on footer column, default is disable. The usage is almost same as [`column.title`](#title),
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerTitle: true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
It's also available to custom via a callback function:
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
footerTitle: function callback(column, colIndex) { ... }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
* `column`: The value of current column.
|
||||||
|
* `colIndex`: The index of the current `column` being processed in `BootstrapTable`.
|
||||||
|
|
||||||
|
## <a name='footerEvents'>column.footerEvents - [Object]</a>
|
||||||
|
`footerEvents` same as [`column.events`](#events) but it is for footer column:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerEvents: {
|
||||||
|
onClick: (e, column, columnIndex) => { ... }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## <a name='footerAlign'>column.footerAlign - [String | Function]</a>
|
||||||
|
It's almost same as [`column.align`](#align), but it's for the [CSS text-align](https://www.w3schools.com/cssref/pr_text_text-align.asp) on footer column.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerAlign: 'center'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Also, you can custom the align by a callback function:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerAlign: (column, colIndex) => {
|
||||||
|
// column is an object and perform itself
|
||||||
|
// return custom title here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Parameters**
|
||||||
|
* `column`: The value of current column.
|
||||||
|
* `colIndex`: The index of the current `column` being processed in `BootstrapTable`.
|
||||||
|
|
||||||
|
## <a name='footerAttrs'>column.footerAttrs - [Object | Function]</a>
|
||||||
|
`footerAttrs` is similar to [`column.attrs`](#attrs) but it works for footer column.
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerAttrs: {
|
||||||
|
title: 'bar',
|
||||||
|
'data-test': 'foo'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Additionally, customize the header attributes by a **2** arguments callback function:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
footerAttrs: (column, colIndex) => ({
|
||||||
|
// return customized HTML attribute here
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
* `column`: The value of current column.
|
||||||
|
* `colIndex`: The index of the current `column` being processed in `BootstrapTable`.
|
||||||
|
|
||||||
## <a name='editable'>column.editable - [Bool | Function]</a>
|
## <a name='editable'>column.editable - [Bool | Function]</a>
|
||||||
`column.editable` default is true, means every column is editable if you configure [`cellEdit`](./README.md#cellEdit). But you can disable some columns editable via setting `false`.
|
`column.editable` default is true, means every column is editable if you configure [`cellEdit`](./README.md#cellEdit). But you can disable some columns editable via setting `false`.
|
||||||
|
|
||||||
@@ -748,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.
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Currently, **I still can't implement all the mainly features in legacy `react-bo
|
|||||||
* [`react-bootstrap-table2-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay)
|
* [`react-bootstrap-table2-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay)
|
||||||
* Overlay/Loading Addons
|
* Overlay/Loading Addons
|
||||||
* [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit)
|
* [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit)
|
||||||
* Table Toolkits, like search, csv etc.
|
* Table Toolkits, like search, csv, column toggle etc.
|
||||||
|
|
||||||
This can help your application with less bundled size and also help `react-bootstrap-table2` have clean design to avoid handling to much logic in kernel module(SRP). Hence, which means you probably need to install above addons when you need specific features.
|
This can help your application with less bundled size and also help `react-bootstrap-table2` have clean design to avoid handling to much logic in kernel module(SRP). Hence, which means you probably need to install above addons when you need specific features.
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ Remember to install [`react-bootstrap-table2-paginator`](https://www.npmjs.com/p
|
|||||||
|
|
||||||
- [x] Custom search component and position
|
- [x] Custom search component and position
|
||||||
- [x] Custom search value
|
- [x] Custom search value
|
||||||
- [ ] Clear search
|
- [x] Clear search
|
||||||
- [ ] Multiple search
|
- [ ] Multiple search
|
||||||
- [ ] Strict search
|
- [ ] Strict search
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Row expand
|
# Row expand
|
||||||
`react-bootstrap-table2` supports the row expand feature. By passing prop `expandRow` to enable this functionality.
|
`react-bootstrap-table2` supports the row expand feature. By passing prop `expandRow` to enable this functionality.
|
||||||
|
|
||||||
> Default is click to expand/collapse a row. In addition, we don't support any way to chagne this mechanism!
|
> Default is click to expand/collapse a row. In addition, we don't support any way to change this mechanism!
|
||||||
|
|
||||||
## Required
|
## Required
|
||||||
* [renderer (**required**)](#renderer)
|
* [renderer (**required**)](#renderer)
|
||||||
@@ -15,8 +15,11 @@
|
|||||||
* [showExpandColumn](#showExpandColumn)
|
* [showExpandColumn](#showExpandColumn)
|
||||||
* [onlyOneExpanding](#onlyOneExpanding)
|
* [onlyOneExpanding](#onlyOneExpanding)
|
||||||
* [expandByColumnOnly](#expandByColumnOnly)
|
* [expandByColumnOnly](#expandByColumnOnly)
|
||||||
|
* [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>
|
||||||
|
|
||||||
@@ -24,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>
|
||||||
@@ -153,3 +157,56 @@ const expandRow = {
|
|||||||
expandByColumnOnly: true
|
expandByColumnOnly: true
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='expandColumnPosition'>expandRow.expandColumnPosition - [String]</a>
|
||||||
|
Default is `left`. You can give this as `right` for rendering expand column in the right side.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const expandRow = {
|
||||||
|
renderer: (row) => ...,
|
||||||
|
showExpandColumn: true,
|
||||||
|
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.
|
||||||
|
|
||||||
@@ -176,7 +229,7 @@ Provide a callback function which allow you to custom the checkbox/radio box. Th
|
|||||||
```js
|
```js
|
||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
selectionRenderer: ({ mode, checked, disabled }) => (
|
selectionRenderer: ({ mode, checked, disabled, rowIndex }) => (
|
||||||
// ....
|
// ....
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@@ -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`.
|
||||||
@@ -249,6 +363,16 @@ const selectRow = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='selectColumnPosition'>selectRow.selectColumnPosition - [String]</a>
|
||||||
|
Default is `left`. You can give this as `right` for rendering selection column in the right side.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
selectColumnPosition: 'right'
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
|
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
|
||||||
Default is `false`, if you don't want to have a selection column, give this prop as `true`
|
Default is `false`, if you don't want to have a selection column, give this prop as `true`
|
||||||
|
|
||||||
|
|||||||
@@ -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,8 @@
|
|||||||
"jest": {
|
"jest": {
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
"packages/*/src/**/*.js",
|
"packages/*/src/**/*.js",
|
||||||
"packages/*/index.js"
|
"packages/*/index.js",
|
||||||
|
"!packages/react-bootstrap-table2-example/**/*.js"
|
||||||
],
|
],
|
||||||
"roots": [
|
"roots": [
|
||||||
"<rootDir>/packages"
|
"<rootDir>/packages"
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|
||||||
@@ -132,7 +175,7 @@ const columns = [
|
|||||||
if (typeof cell !== 'object') {
|
if (typeof cell !== 'object') {
|
||||||
dateObj = new Date(cell);
|
dateObj = new Date(cell);
|
||||||
}
|
}
|
||||||
return `${('0' + dateObj.getDate()).slice(-2)}/${('0' + (dateObj.getMonth() + 1)).slice(-2)}/${dateObj.getFullYear()}`;
|
return `${('0' + dateObj.getUTCDate()).slice(-2)}/${('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/${dateObj.getUTCFullYear()}`;
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.DATE
|
type: Type.DATE
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-editor",
|
"name": "react-bootstrap-table2-editor",
|
||||||
"version": "1.2.2",
|
"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();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const sourceStylePath = path.join(__dirname, '../../react-bootstrap-table2/style
|
|||||||
const paginationStylePath = path.join(__dirname, '../../react-bootstrap-table2-paginator/style');
|
const paginationStylePath = path.join(__dirname, '../../react-bootstrap-table2-paginator/style');
|
||||||
const filterStylePath = path.join(__dirname, '../../react-bootstrap-table2-filter/style');
|
const filterStylePath = path.join(__dirname, '../../react-bootstrap-table2-filter/style');
|
||||||
const toolkitSourcePath = path.join(__dirname, '../../react-bootstrap-table2-toolkit/index.js');
|
const toolkitSourcePath = path.join(__dirname, '../../react-bootstrap-table2-toolkit/index.js');
|
||||||
|
const toolkitStylePath = path.join(__dirname, '../../react-bootstrap-table2-toolkit/style');
|
||||||
const storyPath = path.join(__dirname, '../stories');
|
const storyPath = path.join(__dirname, '../stories');
|
||||||
const examplesPath = path.join(__dirname, '../examples');
|
const examplesPath = path.join(__dirname, '../examples');
|
||||||
const srcPath = path.join(__dirname, '../src');
|
const srcPath = path.join(__dirname, '../src');
|
||||||
@@ -43,7 +44,13 @@ const loaders = [{
|
|||||||
}, {
|
}, {
|
||||||
test: /\.scss$/,
|
test: /\.scss$/,
|
||||||
use: ['style-loader', 'css-loader', 'sass-loader'],
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
||||||
include: [storyPath, sourceStylePath, paginationStylePath, filterStylePath],
|
include: [
|
||||||
|
storyPath,
|
||||||
|
sourceStylePath,
|
||||||
|
paginationStylePath,
|
||||||
|
filterStylePath,
|
||||||
|
toolkitStylePath
|
||||||
|
],
|
||||||
}, {
|
}, {
|
||||||
test: /\.(jpg|png|woff|woff2|eot|ttf|svg)$/,
|
test: /\.(jpg|png|woff|woff2|eot|ttf|svg)$/,
|
||||||
loader: 'url-loader?limit=100000',
|
loader: 'url-loader?limit=100000',
|
||||||
|
|||||||
@@ -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>
|
||||||
|
);
|
||||||
81
packages/react-bootstrap-table2-example/examples/bootstrap4/column-toggle.js
vendored
Normal file
81
packages/react-bootstrap-table2-example/examples/bootstrap4/column-toggle.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
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'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const { ToggleList } = ColumnToggle;
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
90
packages/react-bootstrap-table2-example/examples/bootstrap4/toolkits.js
vendored
Normal file
90
packages/react-bootstrap-table2-example/examples/bootstrap4/toolkits.js
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { Search, CSVExport } from 'react-bootstrap-table2-toolkit';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const { SearchBar, ClearSearchButton } = Search;
|
||||||
|
const { ExportCSVButton } = CSVExport;
|
||||||
|
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, CSVExport } from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const { SearchBar, ClearSearchButton } = Search;
|
||||||
|
const { ExportCSVButton } = CSVExport;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<h3>Input something at below input field:</h3>
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<ClearSearchButton { ...props.searchProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<h3>Input something at below input field:</h3>
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<ClearSearchButton { ...props.searchProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<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>
|
||||||
|
);
|
||||||
@@ -18,6 +18,11 @@ class QualityRanger extends React.Component {
|
|||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
value: 0
|
value: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.range.focus();
|
||||||
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue() {
|
||||||
return parseInt(this.range.value, 10);
|
return parseInt(this.range.value, 10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const columns = [{
|
|||||||
if (typeof cell !== 'object') {
|
if (typeof cell !== 'object') {
|
||||||
dateObj = new Date(cell);
|
dateObj = new Date(cell);
|
||||||
}
|
}
|
||||||
return `${('0' + dateObj.getDate()).slice(-2)}/${('0' + (dateObj.getMonth() + 1)).slice(-2)}/${dateObj.getFullYear()}`;
|
return `${('0' + dateObj.getUTCDate()).slice(-2)}/${('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/${dateObj.getUTCFullYear()}`;
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.DATE
|
type: Type.DATE
|
||||||
@@ -48,7 +48,7 @@ const columns = [{
|
|||||||
if (typeof cell !== 'object') {
|
if (typeof cell !== 'object') {
|
||||||
dateObj = new Date(cell);
|
dateObj = new Date(cell);
|
||||||
}
|
}
|
||||||
return \`$\{('0' + dateObj.getDate()).slice(-2)}/$\{('0' + (dateObj.getMonth() + 1)).slice(-2)}/$\{dateObj.getFullYear()}\`;
|
return \`$\{('0' + dateObj.getUTCDate()).slice(-2)}/$\{('0' + (dateObj.getUTCMonth() + 1)).slice(-2)}/$\{dateObj.getUTCFullYear()}\`;
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
type: Type.DATE
|
type: Type.DATE
|
||||||
|
|||||||
@@ -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>
|
||||||
|
);
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import BootstrapTable from 'react-bootstrap-table-next';
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
import filterFactory, { textFilter, dateFilter } from 'react-bootstrap-table2-filter';
|
||||||
import Code from 'components/common/code-block';
|
import Code from 'components/common/code-block';
|
||||||
import { productsGenerator } from 'utils/common';
|
import { stockGenerator } from 'utils/common';
|
||||||
|
|
||||||
const products = productsGenerator(8);
|
const products = stockGenerator(8);
|
||||||
|
|
||||||
let nameFilter;
|
let nameFilter;
|
||||||
let priceFilter;
|
let priceFilter;
|
||||||
|
let stockDateFilter;
|
||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
@@ -22,25 +23,36 @@ const columns = [{
|
|||||||
})
|
})
|
||||||
}, {
|
}, {
|
||||||
dataField: 'price',
|
dataField: 'price',
|
||||||
text: 'Product Price',
|
text: 'Price',
|
||||||
filter: textFilter({
|
filter: textFilter({
|
||||||
getFilter: (filter) => {
|
getFilter: (filter) => {
|
||||||
priceFilter = filter;
|
priceFilter = filter;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}, {
|
||||||
|
dataField: 'inStockDate',
|
||||||
|
text: 'InStock Date',
|
||||||
|
formatter: cell => cell.toString(),
|
||||||
|
filter: dateFilter({
|
||||||
|
getFilter: (filter) => {
|
||||||
|
stockDateFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
nameFilter('');
|
nameFilter('');
|
||||||
priceFilter('');
|
priceFilter('');
|
||||||
|
stockDateFilter();
|
||||||
};
|
};
|
||||||
|
|
||||||
const sourceCode = `\
|
const sourceCode = `\
|
||||||
import BootstrapTable from 'react-bootstrap-table-next';
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
import filterFactory, { textFilter, dateFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
let nameFilter;
|
let nameFilter;
|
||||||
let priceFilter;
|
let priceFilter;
|
||||||
|
let stockDateFilter;
|
||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
@@ -55,17 +67,27 @@ const columns = [{
|
|||||||
})
|
})
|
||||||
}, {
|
}, {
|
||||||
dataField: 'price',
|
dataField: 'price',
|
||||||
text: 'Product Price',
|
text: 'Price',
|
||||||
filter: textFilter({
|
filter: textFilter({
|
||||||
getFilter: (filter) => {
|
getFilter: (filter) => {
|
||||||
priceFilter = filter;
|
priceFilter = filter;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}, {
|
||||||
|
dataField: 'inStockDate',
|
||||||
|
text: 'InStock Date',
|
||||||
|
formatter: cell => cell.toString(),
|
||||||
|
filter: dateFilter({
|
||||||
|
getFilter: (filter) => {
|
||||||
|
stockDateFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
nameFilter('');
|
nameFilter('');
|
||||||
priceFilter('');
|
priceFilter('');
|
||||||
|
stockDateFilter();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default () => (
|
export default () => (
|
||||||
|
|||||||
89
packages/react-bootstrap-table2-example/examples/column-filter/custom-filter-logic.js
vendored
Normal file
89
packages/react-bootstrap-table2-example/examples/column-filter/custom-filter-logic.js
vendored
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/* eslint eqeqeq: 0 */
|
||||||
|
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 sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
class Table extends React.Component {
|
||||||
|
filterByPrice = (filterVal, data) => {
|
||||||
|
if (filterVal) {
|
||||||
|
return data.filter(product => product.price == filterVal);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter({
|
||||||
|
onFilter: this.filterByPrice
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class Table extends React.Component {
|
||||||
|
filterByPrice = (filterVal, data) => {
|
||||||
|
if (filterVal) {
|
||||||
|
return data.filter(product => product.price == filterVal);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter({
|
||||||
|
onFilter: this.filterByPrice
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>Implement a eq price filter</h2>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
packages/react-bootstrap-table2-example/examples/column-filter/filter-hooks.js
vendored
Normal file
57
packages/react-bootstrap-table2-example/examples/column-filter/filter-hooks.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/* eslint no-console: 0 */
|
||||||
|
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({
|
||||||
|
onFilter: filterVal => console.log(`Filter Value: ${filterVal}`)
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
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({
|
||||||
|
onFilter: filterVal => console.log(\`Filter Value: $\{filterVal}\`)
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
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>
|
||||||
|
);
|
||||||
135
packages/react-bootstrap-table2-example/examples/column-toggle/custom-toggle-list.js
vendored
Normal file
135
packages/react-bootstrap-table2-example/examples/column-toggle/custom-toggle-list.js
vendored
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider from 'react-bootstrap-table2-toolkit';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator();
|
||||||
|
|
||||||
|
const columnsdt = [{
|
||||||
|
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 from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const CustomToggleList = ({
|
||||||
|
columns,
|
||||||
|
onColumnToggle,
|
||||||
|
toggles
|
||||||
|
}) => (
|
||||||
|
<div className="btn-group btn-group-toggle btn-group-vertical" data-toggle="buttons">
|
||||||
|
{
|
||||||
|
columns
|
||||||
|
.map(column => ({
|
||||||
|
...column,
|
||||||
|
toggle: toggles[column.dataField]
|
||||||
|
}))
|
||||||
|
.map(column => (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
key={ column.dataField }
|
||||||
|
className={ \`btn btn-warning \${column.toggle ? 'active' : ''}\` }
|
||||||
|
data-toggle="button"
|
||||||
|
aria-pressed={ column.toggle ? 'true' : 'false' }
|
||||||
|
onClick={ () => onColumnToggle(column.dataField) }
|
||||||
|
>
|
||||||
|
{ column.text }
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columnsdt }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<CustomToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const CustomToggleList = ({
|
||||||
|
columns,
|
||||||
|
onColumnToggle,
|
||||||
|
toggles
|
||||||
|
}) => (
|
||||||
|
<div className="btn-group btn-group-toggle btn-group-vertical" data-toggle="buttons">
|
||||||
|
{
|
||||||
|
columns
|
||||||
|
.map(column => ({
|
||||||
|
...column,
|
||||||
|
toggle: toggles[column.dataField]
|
||||||
|
}))
|
||||||
|
.map(column => (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
key={ column.dataField }
|
||||||
|
className={ `btn btn-warning ${column.toggle ? 'active' : ''}` }
|
||||||
|
data-toggle="button"
|
||||||
|
aria-pressed={ column.toggle ? 'true' : 'false' }
|
||||||
|
onClick={ () => onColumnToggle(column.dataField) }
|
||||||
|
>
|
||||||
|
{ column.text }
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columnsdt }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<CustomToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
81
packages/react-bootstrap-table2-example/examples/column-toggle/default-visibility.js
vendored
Normal file
81
packages/react-bootstrap-table2-example/examples/column-toggle/default-visibility.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
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',
|
||||||
|
hidden: true
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
hidden: true
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const { ToggleList } = ColumnToggle;
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
hidden: true
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
hidden: true
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable { ...props.baseProps } />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable { ...props.baseProps } />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
81
packages/react-bootstrap-table2-example/examples/column-toggle/index.js
vendored
Normal file
81
packages/react-bootstrap-table2-example/examples/column-toggle/index.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
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'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const { ToggleList } = ColumnToggle;
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList { ...props.columnToggleProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
91
packages/react-bootstrap-table2-example/examples/column-toggle/styling-toggle-list.js
vendored
Normal file
91
packages/react-bootstrap-table2-example/examples/column-toggle/styling-toggle-list.js
vendored
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
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'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
|
||||||
|
|
||||||
|
const { ToggleList } = ColumnToggle;
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList
|
||||||
|
contextual="success"
|
||||||
|
className="list-custom-class"
|
||||||
|
btnClassName="list-btn-custom-class"
|
||||||
|
{ ...props.columnToggleProps }
|
||||||
|
/>
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
columnToggle
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ToggleList
|
||||||
|
contextual="success"
|
||||||
|
className="list-custom-class"
|
||||||
|
btnClassName="list-btn-custom-class"
|
||||||
|
{ ...props.columnToggleProps }
|
||||||
|
/>
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -11,141 +11,13 @@ const products = [
|
|||||||
{ id: 14, name: 'Item 14', price: 14.5, inStock: true }
|
{ id: 14, name: 'Item 14', price: 14.5, inStock: true }
|
||||||
];
|
];
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
dataField: 'id',
|
|
||||||
text: 'Product ID'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Product Name'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'price',
|
|
||||||
text: 'Product Price'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'inStock',
|
|
||||||
text: 'In Stock',
|
|
||||||
formatter: (cellContent, row) => (
|
|
||||||
<div className="checkbox disabled">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" checked={ row.inStock } disabled />
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'df1',
|
|
||||||
isDummyField: true,
|
|
||||||
text: 'Action 1',
|
|
||||||
formatter: (cellContent, row) => {
|
|
||||||
if (row.inStock) {
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-success"> Available</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-danger"> Backordered</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'df2',
|
|
||||||
isDummyField: true,
|
|
||||||
text: 'Action 2',
|
|
||||||
formatter: (cellContent, row) => {
|
|
||||||
if (row.inStock) {
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-success"> Available</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-danger"> Backordered</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const sourceCode = `\
|
const sourceCode = `\
|
||||||
import BootstrapTable from 'react-bootstrap-table-next';
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
dataField: 'id',
|
|
||||||
text: 'Product ID'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Product Name'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'price',
|
|
||||||
text: 'Product Price'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'inStock',
|
|
||||||
text: 'In Stock',
|
|
||||||
formatter: (cellContent, row) => (
|
|
||||||
<div className="checkbox disabled">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" checked={ row.inStock } disabled />
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'df1',
|
|
||||||
isDummyField: true,
|
|
||||||
text: 'Action 1',
|
|
||||||
formatter: (cellContent, row) => {
|
|
||||||
if (row.inStock) {
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-success"> Available</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-danger"> Backordered</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataField: 'df2',
|
|
||||||
isDummyField: true,
|
|
||||||
text: 'Action 2',
|
|
||||||
formatter: (cellContent, row) => {
|
|
||||||
if (row.inStock) {
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-success"> Available</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<h5>
|
|
||||||
<span className="label label-danger"> Backordered</span>
|
|
||||||
</h5>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
class ProductList extends React.Component {
|
class ProductList extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { products };
|
this.state = { products, count: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleInStock = () => {
|
toggleInStock = () => {
|
||||||
@@ -163,17 +35,96 @@ class ProductList extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
formatter: (cell, row, rowIndex, extraData) => (
|
||||||
|
<div>
|
||||||
|
<span>ID: {row.id}</span>
|
||||||
|
<br />
|
||||||
|
<span>state: {extraData}</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
formatExtraData: this.state.count
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'inStock',
|
||||||
|
text: 'In Stock',
|
||||||
|
formatter: (cellContent, row) => (
|
||||||
|
<div className="checkbox disabled">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" checked={ row.inStock } disabled />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'df1',
|
||||||
|
isDummyField: true,
|
||||||
|
text: 'Action 1',
|
||||||
|
formatter: (cellContent, row) => {
|
||||||
|
if (row.inStock) {
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-success"> Available</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-danger"> Backordered</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'df2',
|
||||||
|
isDummyField: true,
|
||||||
|
text: 'Action 2',
|
||||||
|
formatter: (cellContent, row) => {
|
||||||
|
if (row.inStock) {
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-success"> Available</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-danger"> Backordered</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1 className="h2">Products</h1>
|
<h3>Action 1 and Action 2 are dummy column</h3>
|
||||||
|
<button onClick={ this.toggleInStock } className="btn btn-primary">
|
||||||
|
Toggle item 13 stock status
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn btn-success"
|
||||||
|
onClick={ () => this.setState(() => ({ count: this.state.count + 1 })) }
|
||||||
|
>
|
||||||
|
Click me to Increase counter
|
||||||
|
</button>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
keyField="id"
|
||||||
data={ this.state.products }
|
data={ this.state.products }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
/>
|
/>
|
||||||
<button onClick={ this.toggleInStock } className="btn btn-primary">
|
<Code>{ sourceCode }</Code>
|
||||||
Toggle item 13 stock status
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -183,7 +134,7 @@ class ProductList extends React.Component {
|
|||||||
class ProductList extends React.Component {
|
class ProductList extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { products };
|
this.state = { products, count: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleInStock = () => {
|
toggleInStock = () => {
|
||||||
@@ -200,13 +151,95 @@ class ProductList extends React.Component {
|
|||||||
this.setState(curr => ({ ...curr, products: newProducts }));
|
this.setState(curr => ({ ...curr, products: newProducts }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
counter = () => {
|
||||||
|
this.setState(curr => ({ ...curr, count: this.state.count + 1 }));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
formatter: (cell, row, rowIndex, extraData) => (
|
||||||
|
<div>
|
||||||
|
<span>ID: {row.id}</span>
|
||||||
|
<br />
|
||||||
|
<span>Counter: {extraData}</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
formatExtraData: this.state.count
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'inStock',
|
||||||
|
text: 'In Stock',
|
||||||
|
formatter: (cellContent, row) => (
|
||||||
|
<div className="checkbox disabled">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" checked={ row.inStock } disabled />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'df1',
|
||||||
|
isDummyField: true,
|
||||||
|
text: 'Action 1',
|
||||||
|
formatter: (cellContent, row) => {
|
||||||
|
if (row.inStock) {
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-success"> Available</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-danger"> Backordered</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'df2',
|
||||||
|
isDummyField: true,
|
||||||
|
text: 'Action 2',
|
||||||
|
formatter: (cellContent, row) => {
|
||||||
|
if (row.inStock) {
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-success"> Available</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<span className="label label-danger"> Backordered</span>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h3>Action 1 and Action 2 are dummy column</h3>
|
<h3>Action 1 and Action 2 are dummy column</h3>
|
||||||
<button onClick={ this.toggleInStock } className="btn btn-primary">
|
<button onClick={ this.toggleInStock } className="btn btn-primary">
|
||||||
Toggle item 13 stock status
|
Toggle item 13 stock status
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn btn-success"
|
||||||
|
onClick={ this.counter }
|
||||||
|
>
|
||||||
|
Click me to Increase counter
|
||||||
|
</button>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
keyField="id"
|
||||||
data={ this.state.products }
|
data={ this.state.products }
|
||||||
|
|||||||
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>
|
||||||
|
);
|
||||||
102
packages/react-bootstrap-table2-example/examples/csv/export-only-filtered.js
vendored
Normal file
102
packages/react-bootstrap-table2-example/examples/csv/export-only-filtered.js
vendored
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { CSVExport, Search } from 'react-bootstrap-table2-toolkit';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const { SearchBar } = Search;
|
||||||
|
const { ExportCSVButton } = CSVExport;
|
||||||
|
const products = productsGenerator(150);
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import ToolkitProvider, { CSVExport, Search } from 'react-bootstrap-table2-toolkit';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
const { SearchBar } = Search;
|
||||||
|
const { ExportCSVButton } = CSVExport;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true
|
||||||
|
};
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
exportCSV={ { onlyExportFiltered: true, exportAll: false } }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||||
|
<hr />
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<h3>Export all the filtered/searched rows</h3>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
exportCSV={ { onlyExportFiltered: true, exportAll: false } }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||||
|
<hr />
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
151
packages/react-bootstrap-table2-example/examples/data/data-change-listener.js
vendored
Normal file
151
packages/react-bootstrap-table2-example/examples/data/data-change-listener.js
vendored
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/* eslint react/no-multi-comp: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
|
class Case1 extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { rowCount: products.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDataChange = ({ dataSize }) => {
|
||||||
|
this.setState({ rowCount: dataSize });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h5>Row Count:<span className="badge">{ this.state.rowCount }</span></h5>
|
||||||
|
<BootstrapTable
|
||||||
|
onDataSizeChange={ this.handleDataChange }
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const sourceCode2 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
|
||||||
|
class Case2 extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { rowCount: products.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDataChange = ({ dataSize }) => {
|
||||||
|
this.setState({ rowCount: dataSize });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h5>Row Count:<span className="badge">{ this.state.rowCount }</span></h5>
|
||||||
|
<BootstrapTable
|
||||||
|
onDataSizeChange={ this.handleDataChange }
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const products1 = productsGenerator(8);
|
||||||
|
class WithoutPaginationCase extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { rowCount: products1.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDataChange = ({ dataSize }) => {
|
||||||
|
this.setState({ rowCount: dataSize });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3>Without Pagination Case</h3>
|
||||||
|
<h5>Row Count:<span className="badge">{ this.state.rowCount }</span></h5>
|
||||||
|
<BootstrapTable
|
||||||
|
onDataSizeChange={ this.handleDataChange }
|
||||||
|
keyField="id"
|
||||||
|
data={ products1 }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode2 }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const products2 = productsGenerator(88);
|
||||||
|
class WithPaginationCase extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { rowCount: products2.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDataChange = ({ dataSize }) => {
|
||||||
|
this.setState({ rowCount: dataSize });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3>Without Pagination Case</h3>
|
||||||
|
<h5>Row Count:<span className="badge">{ this.state.rowCount }</span></h5>
|
||||||
|
<BootstrapTable
|
||||||
|
onDataSizeChange={ this.handleDataChange }
|
||||||
|
keyField="id"
|
||||||
|
data={ products2 }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode1 }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<WithoutPaginationCase />
|
||||||
|
<WithPaginationCase />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/* 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 { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const ProductList = (props) => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter({
|
||||||
|
defaultValue: '1'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={ { paddingTop: '20px' } }>
|
||||||
|
<h1 className="h2">Products</h1>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ props.products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class DataContainer extends React.Component {
|
||||||
|
state = {
|
||||||
|
products: productsGenerator(3)
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({
|
||||||
|
products: productsGenerator(14)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={ this.loadData }
|
||||||
|
style={ {
|
||||||
|
fontSize: '20px',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '200px',
|
||||||
|
top: '40px'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
Load Data
|
||||||
|
</button>
|
||||||
|
<ProductList products={ this.state.products } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/* 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 { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const { SearchBar } = Search;
|
||||||
|
const ProductList = (props) => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={ { paddingTop: '20px' } }>
|
||||||
|
<h1 className="h2">Products</h1>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ props.products }
|
||||||
|
columns={ columns }
|
||||||
|
search={ { defaultSearch: '2101' } }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
toolkitprops => (
|
||||||
|
<div>
|
||||||
|
<SearchBar { ...toolkitprops.searchProps } />
|
||||||
|
<BootstrapTable
|
||||||
|
striped
|
||||||
|
hover
|
||||||
|
{ ...toolkitprops.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class DataContainer extends React.Component {
|
||||||
|
state = {
|
||||||
|
products: productsGenerator(3)
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({
|
||||||
|
products: productsGenerator(14)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={ this.loadData }
|
||||||
|
style={ {
|
||||||
|
fontSize: '20px',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '200px',
|
||||||
|
top: '40px'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
Load Data
|
||||||
|
</button>
|
||||||
|
<ProductList products={ this.state.products } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
68
packages/react-bootstrap-table2-example/examples/data/load-data-on-the-fly-with-filter.js
vendored
Normal file
68
packages/react-bootstrap-table2-example/examples/data/load-data-on-the-fly-with-filter.js
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* 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 { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const ProductList = (props) => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={ { paddingTop: '20px' } }>
|
||||||
|
<h1 className="h2">Products</h1>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ props.products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class DataContainer extends React.Component {
|
||||||
|
state = {
|
||||||
|
products: []
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({
|
||||||
|
products: productsGenerator()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={ this.loadData }
|
||||||
|
style={ {
|
||||||
|
fontSize: '20px',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '200px',
|
||||||
|
top: '40px'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
Load Data
|
||||||
|
</button>
|
||||||
|
<ProductList products={ this.state.products } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/* 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 paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const ProductList = (props) => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter({
|
||||||
|
defaultValue: '6'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={ { paddingTop: '20px' } }>
|
||||||
|
<h1 className="h2">Products</h1>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ props.products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class DataContainer extends React.Component {
|
||||||
|
state = {
|
||||||
|
products: productsGenerator(60)
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({
|
||||||
|
products: productsGenerator(14)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={ this.loadData }
|
||||||
|
style={ {
|
||||||
|
fontSize: '20px',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '200px',
|
||||||
|
top: '40px'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
Load Data
|
||||||
|
</button>
|
||||||
|
<ProductList products={ this.state.products } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
80
packages/react-bootstrap-table2-example/examples/data/load-data-on-the-fly-with-search.js
vendored
Normal file
80
packages/react-bootstrap-table2-example/examples/data/load-data-on-the-fly-with-search.js
vendored
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/* 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 { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const { SearchBar } = Search;
|
||||||
|
const ProductList = (props) => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={ { paddingTop: '20px' } }>
|
||||||
|
<h1 className="h2">Products</h1>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ props.products }
|
||||||
|
columns={ columns }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
toolkitprops => (
|
||||||
|
<div>
|
||||||
|
<SearchBar { ...toolkitprops.searchProps } />
|
||||||
|
<BootstrapTable
|
||||||
|
striped
|
||||||
|
hover
|
||||||
|
{ ...toolkitprops.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class DataContainer extends React.Component {
|
||||||
|
state = {
|
||||||
|
products: []
|
||||||
|
};
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({
|
||||||
|
products: productsGenerator()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={ this.loadData }
|
||||||
|
style={ {
|
||||||
|
fontSize: '20px',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '200px',
|
||||||
|
top: '40px'
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
Load Data
|
||||||
|
</button>
|
||||||
|
<ProductList products={ this.state.products } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
53
packages/react-bootstrap-table2-example/examples/footer/column-align-table.js
vendored
Normal file
53
packages/react-bootstrap-table2-example/examples/footer/column-align-table.js
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* 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',
|
||||||
|
footerAlign: 'center',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footerAlign: (column, colIndex) => 'right',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footerAlign: 'center',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footerAlign: (column, colIndex) => 'right',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
54
packages/react-bootstrap-table2-example/examples/footer/column-attrs-table.js
vendored
Normal file
54
packages/react-bootstrap-table2-example/examples/footer/column-attrs-table.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
/* eslint no-alert: 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',
|
||||||
|
footer: 'Footer 1',
|
||||||
|
footerAttrs: { title: 'ID footer column' }
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2',
|
||||||
|
footerAttrs: (column, colIndex) => ({ 'data-test': `customized data ${colIndex}` })
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footer: 'Footer 1',
|
||||||
|
footerAttrs: { title: 'ID footer column' }
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2',
|
||||||
|
footerAttrs: (column, colIndex) => ({ 'data-test': \`customized data \${colIndex}\` })
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
60
packages/react-bootstrap-table2-example/examples/footer/column-class-table.js
vendored
Normal file
60
packages/react-bootstrap-table2-example/examples/footer/column-class-table.js
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
/* eslint no-alert: 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',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2',
|
||||||
|
footerClasses: 'demo-row-odd'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3',
|
||||||
|
footerClasses: (column, colIndex) => {
|
||||||
|
if (colIndex % 2 === 0) return 'demo-row-even';
|
||||||
|
return 'demo-row-odd';
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2',
|
||||||
|
footerClasses: 'demo-row-odd'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3',
|
||||||
|
footerClasses: (column, colIndex) => {
|
||||||
|
if (colIndex % 2 === 0) return 'demo-row-even';
|
||||||
|
return 'demo-row-odd';
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
56
packages/react-bootstrap-table2-example/examples/footer/column-event-table.js
vendored
Normal file
56
packages/react-bootstrap-table2-example/examples/footer/column-event-table.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
/* eslint no-alert: 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',
|
||||||
|
footerEvents: {
|
||||||
|
onClick: (e, column, columnIndex) => alert(`Click on Product ID header column, columnIndex: ${columnIndex}`)
|
||||||
|
},
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footerEvents: {
|
||||||
|
onClick: (e, column, columnIndex) => alert('Click on Product ID footer column')
|
||||||
|
},
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
67
packages/react-bootstrap-table2-example/examples/footer/column-format-table.js
vendored
Normal file
67
packages/react-bootstrap-table2-example/examples/footer/column-format-table.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/* 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();
|
||||||
|
|
||||||
|
function priceFormatter(column, colIndex) {
|
||||||
|
return (
|
||||||
|
<h5>
|
||||||
|
<strong>$$ {column.text} $$</strong>
|
||||||
|
</h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
footerFormatter: priceFormatter
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
function priceFormatter(column, colIndex) {
|
||||||
|
return (
|
||||||
|
<h5><strong>$$ { column.text } $$</strong></h5>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
// omit...
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3',
|
||||||
|
footerFormatter: priceFormatter
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{sourceCode}</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
76
packages/react-bootstrap-table2-example/examples/footer/column-style-table.js
vendored
Normal file
76
packages/react-bootstrap-table2-example/examples/footer/column-style-table.js
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
/* eslint no-alert: 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',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2',
|
||||||
|
footerStyle: {
|
||||||
|
backgroundColor: '#c8e6c9'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3',
|
||||||
|
footerStyle: (column, colIndex) => {
|
||||||
|
if (colIndex % 2 === 0) {
|
||||||
|
return {
|
||||||
|
backgroundColor: '#81c784'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
backgroundColor: '#c8e6c9'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2',
|
||||||
|
footerStyle: {
|
||||||
|
backgroundColor: '#c8e6c9'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3',
|
||||||
|
footerStyle: (column, colIndex) => {
|
||||||
|
if (colIndex % 2 === 0) {
|
||||||
|
return {
|
||||||
|
backgroundColor: '#81c784'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
backgroundColor: '#c8e6c9'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
53
packages/react-bootstrap-table2-example/examples/footer/column-title-table.js
vendored
Normal file
53
packages/react-bootstrap-table2-example/examples/footer/column-title-table.js
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* 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',
|
||||||
|
footerTitle: true,
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footerTitle: (column, colIndex) => `this is custom title for ${column.text}`,
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
footerTitle: true,
|
||||||
|
footer: 'Footer 1'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footerTitle: (column, colIndex) => \`this is custom title for \${column.text}\`,
|
||||||
|
footer: 'Footer 2'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
61
packages/react-bootstrap-table2-example/examples/footer/footer-class-table.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/footer/footer-class-table.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',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
footerClasses="footer-class"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } footerClasses="footer-class" />
|
||||||
|
<Code>{sourceCode}</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
52
packages/react-bootstrap-table2-example/examples/footer/function-footer.js
vendored
Normal file
52
packages/react-bootstrap-table2-example/examples/footer/function-footer.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* 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',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: columnData => columnData.reduce((acc, item) => acc + item, 0)
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
// omit...
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: columnData => columnData.reduce((acc, item) => acc + item, 0)
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{sourceCode}</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
52
packages/react-bootstrap-table2-example/examples/footer/simple-footer.js
vendored
Normal file
52
packages/react-bootstrap-table2-example/examples/footer/simple-footer.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* 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',
|
||||||
|
footer: 'Footer 1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
footer: 'Footer 2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
// omit...
|
||||||
|
{
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
footer: 'Footer 3'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{sourceCode}</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -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>
|
||||||
|
|||||||
159
packages/react-bootstrap-table2-example/examples/pagination/custom-page-list-with-search.js
vendored
Normal file
159
packages/react-bootstrap-table2-example/examples/pagination/custom-page-list-with-search.js
vendored
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/* eslint react/prefer-stateless-function: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(40);
|
||||||
|
const { SearchBar } = Search;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
class Table extends React.Component {
|
||||||
|
state = { products }
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({ products: productsGenerator(17) });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = {
|
||||||
|
custom: true,
|
||||||
|
paginationSize: 4,
|
||||||
|
pageStartIndex: 1,
|
||||||
|
firstPageText: 'First',
|
||||||
|
prePageText: 'Back',
|
||||||
|
nextPageText: 'Next',
|
||||||
|
lastPageText: 'Last',
|
||||||
|
nextPageTitle: 'First page',
|
||||||
|
prePageTitle: 'Pre page',
|
||||||
|
firstPageTitle: 'Next page',
|
||||||
|
lastPageTitle: 'Last page',
|
||||||
|
showTotal: true,
|
||||||
|
totalSize: this.state.products.length
|
||||||
|
};
|
||||||
|
const contentTable = ({ paginationProps, paginationTableProps }) => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
columns={ columns }
|
||||||
|
data={ this.state.products }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
toolkitprops => (
|
||||||
|
<div>
|
||||||
|
<SearchBar { ...toolkitprops.searchProps } />
|
||||||
|
<BootstrapTable
|
||||||
|
striped
|
||||||
|
hover
|
||||||
|
{ ...toolkitprops.baseProps }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>PaginationProvider will care the data size change. You dont do anything</h2>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={
|
||||||
|
paginationFactory(options)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ contentTable }
|
||||||
|
</PaginationProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class Table extends React.Component {
|
||||||
|
state = { products }
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({ products: productsGenerator(17) });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = {
|
||||||
|
custom: true,
|
||||||
|
paginationSize: 4,
|
||||||
|
pageStartIndex: 1,
|
||||||
|
firstPageText: 'First',
|
||||||
|
prePageText: 'Back',
|
||||||
|
nextPageText: 'Next',
|
||||||
|
lastPageText: 'Last',
|
||||||
|
nextPageTitle: 'First page',
|
||||||
|
prePageTitle: 'Pre page',
|
||||||
|
firstPageTitle: 'Next page',
|
||||||
|
lastPageTitle: 'Last page',
|
||||||
|
showTotal: true,
|
||||||
|
totalSize: this.state.products.length
|
||||||
|
};
|
||||||
|
const contentTable = ({ paginationProps, paginationTableProps }) => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
columns={ columns }
|
||||||
|
data={ this.state.products }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
toolkitprops => (
|
||||||
|
<div>
|
||||||
|
<SearchBar { ...toolkitprops.searchProps } />
|
||||||
|
<BootstrapTable
|
||||||
|
striped
|
||||||
|
hover
|
||||||
|
{ ...toolkitprops.baseProps }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>PaginationProvider will care the data size change. You dont do anything</h2>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={
|
||||||
|
paginationFactory(options)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ contentTable }
|
||||||
|
</PaginationProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</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',
|
||||||
|
|||||||
181
packages/react-bootstrap-table2-example/examples/pagination/custome-page-list-with-filter.js
vendored
Normal file
181
packages/react-bootstrap-table2-example/examples/pagination/custome-page-list-with-filter.js
vendored
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
/* eslint react/prefer-stateless-function: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
import filterFactory, { textFilter, selectFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsQualityGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsQualityGenerator(21);
|
||||||
|
|
||||||
|
const selectOptions = {
|
||||||
|
0: 'good',
|
||||||
|
1: 'Bad',
|
||||||
|
2: 'unknown'
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'quality',
|
||||||
|
text: 'Product Quailty',
|
||||||
|
formatter: cell => selectOptions[cell],
|
||||||
|
filter: selectFilter({
|
||||||
|
options: selectOptions,
|
||||||
|
defaultValue: 0
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
import filterFactory, { textFilter, selectFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
const selectOptions = {
|
||||||
|
0: 'good',
|
||||||
|
1: 'Bad',
|
||||||
|
2: 'unknown'
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'quality',
|
||||||
|
text: 'Product Quailty',
|
||||||
|
formatter: cell => selectOptions[cell],
|
||||||
|
filter: selectFilter({
|
||||||
|
options: selectOptions,
|
||||||
|
defaultValue: 0
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
class Table extends React.Component {
|
||||||
|
state = { products }
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({ products: productsQualityGenerator(40, 7) });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = {
|
||||||
|
custom: true,
|
||||||
|
paginationSize: 4,
|
||||||
|
pageStartIndex: 1,
|
||||||
|
firstPageText: 'First',
|
||||||
|
prePageText: 'Back',
|
||||||
|
nextPageText: 'Next',
|
||||||
|
lastPageText: 'Last',
|
||||||
|
nextPageTitle: 'First page',
|
||||||
|
prePageTitle: 'Pre page',
|
||||||
|
firstPageTitle: 'Next page',
|
||||||
|
lastPageTitle: 'Last page',
|
||||||
|
showTotal: true,
|
||||||
|
totalSize: this.state.products.length
|
||||||
|
};
|
||||||
|
const contentTable = ({ paginationProps, paginationTableProps }) => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
striped
|
||||||
|
hover
|
||||||
|
keyField="id"
|
||||||
|
data={ this.state.products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>PaginationProvider will care the data size change. You dont do anything</h2>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={
|
||||||
|
paginationFactory(options)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ contentTable }
|
||||||
|
</PaginationProvider>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class Table extends React.Component {
|
||||||
|
state = { products }
|
||||||
|
|
||||||
|
loadData = () => {
|
||||||
|
this.setState({ products: productsQualityGenerator(40, 7) });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = {
|
||||||
|
custom: true,
|
||||||
|
paginationSize: 4,
|
||||||
|
pageStartIndex: 1,
|
||||||
|
firstPageText: 'First',
|
||||||
|
prePageText: 'Back',
|
||||||
|
nextPageText: 'Next',
|
||||||
|
lastPageText: 'Last',
|
||||||
|
nextPageTitle: 'First page',
|
||||||
|
prePageTitle: 'Pre page',
|
||||||
|
firstPageTitle: 'Next page',
|
||||||
|
lastPageTitle: 'Last page',
|
||||||
|
showTotal: true,
|
||||||
|
totalSize: this.state.products.length
|
||||||
|
};
|
||||||
|
const contentTable = ({ paginationProps, paginationTableProps }) => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
striped
|
||||||
|
hover
|
||||||
|
keyField="id"
|
||||||
|
data={ this.state.products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<PaginationListStandalone { ...paginationProps } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>PaginationProvider will care the data size change. You dont do anything</h2>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={
|
||||||
|
paginationFactory(options)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ contentTable }
|
||||||
|
</PaginationProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
150
packages/react-bootstrap-table2-example/examples/pagination/pagination-with-dynamic-data.js
vendored
Normal file
150
packages/react-bootstrap-table2-example/examples/pagination/pagination-with-dynamic-data.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
|
||||||
|
class BookList extends React.Component {
|
||||||
|
state = {
|
||||||
|
books: [
|
||||||
|
{ id: '1', name: 'Book 1' },
|
||||||
|
{ id: '2', name: 'Book 2' },
|
||||||
|
{ id: '3', name: 'Book 3' },
|
||||||
|
{ id: '4', name: 'Book 4' },
|
||||||
|
{ id: '5', name: 'Book 5' },
|
||||||
|
{ id: '6', name: 'Book 6' }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteBookWithId = () => {
|
||||||
|
const lastOneId = this.state.books.length;
|
||||||
|
const updatedBooks = this.state.books.filter(m => m.id !== lastOneId.toString());
|
||||||
|
this.setState({ books: updatedBooks });
|
||||||
|
};
|
||||||
|
|
||||||
|
addBook = () => {
|
||||||
|
const lastOneId = this.state.books.length + 1;
|
||||||
|
this.setState({ books: [...this.state.books, {
|
||||||
|
id: \`$\{lastOneId}\`, name: \`Book $\{lastOneId}\`
|
||||||
|
}] });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = {
|
||||||
|
// pageStartIndex: 0,
|
||||||
|
sizePerPage: 5,
|
||||||
|
hideSizePerPage: true,
|
||||||
|
hidePageListOnlyOnePage: true
|
||||||
|
};
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
Cell: row => (
|
||||||
|
<div>
|
||||||
|
<span title={ row.value }>{ row.value }</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ this.state.books }
|
||||||
|
columns={ columns }
|
||||||
|
pagination={ paginationFactory(options) }
|
||||||
|
/>
|
||||||
|
<button className="btn btn-default" onClick={ () => this.deleteBookWithId() }>
|
||||||
|
delete last one book
|
||||||
|
</button>
|
||||||
|
<button className="btn btn-default" onClick={ () => this.addBook() }>
|
||||||
|
Add a book to the end
|
||||||
|
</button>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class BookList extends React.Component {
|
||||||
|
state = {
|
||||||
|
books: [
|
||||||
|
{ id: '1', name: 'Book 1' },
|
||||||
|
{ id: '2', name: 'Book 2' },
|
||||||
|
{ id: '3', name: 'Book 3' },
|
||||||
|
{ id: '4', name: 'Book 4' },
|
||||||
|
{ id: '5', name: 'Book 5' },
|
||||||
|
{ id: '6', name: 'Book 6' },
|
||||||
|
{ id: '7', name: 'Book 6' },
|
||||||
|
{ id: '8', name: 'Book 6' },
|
||||||
|
{ id: '9', name: 'Book 6' },
|
||||||
|
{ id: '10', name: 'Book 6' },
|
||||||
|
{ id: '11', name: 'Book 6' }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteBookWithId = () => {
|
||||||
|
const lastOneId = this.state.books.length;
|
||||||
|
const updatedBooks = this.state.books.filter(m => m.id !== lastOneId.toString());
|
||||||
|
this.setState({ books: updatedBooks });
|
||||||
|
};
|
||||||
|
|
||||||
|
addBook = () => {
|
||||||
|
const lastOneId = this.state.books.length + 1;
|
||||||
|
this.setState({ books: [...this.state.books, {
|
||||||
|
id: `${lastOneId}`, name: `Book ${lastOneId}`
|
||||||
|
}] });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = {
|
||||||
|
// pageStartIndex: 0,
|
||||||
|
sizePerPage: 5,
|
||||||
|
hideSizePerPage: true,
|
||||||
|
hidePageListOnlyOnePage: true
|
||||||
|
};
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
Cell: row => (
|
||||||
|
<div>
|
||||||
|
<span title={ row.value }>{ row.value }</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ this.state.books }
|
||||||
|
columns={ columns }
|
||||||
|
pagination={ paginationFactory(options) }
|
||||||
|
/>
|
||||||
|
<button className="btn btn-default" onClick={ () => this.deleteBookWithId() }>
|
||||||
|
delete last one book
|
||||||
|
</button>
|
||||||
|
<button className="btn btn-default" onClick={ () => this.addBook() }>
|
||||||
|
Add a book to the end
|
||||||
|
</button>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
190
packages/react-bootstrap-table2-example/examples/pagination/remote-standalone-pagination.js
vendored
Normal file
190
packages/react-bootstrap-table2-example/examples/pagination/remote-standalone-pagination.js
vendored
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
/* eslint react/no-multi-comp: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(87);
|
||||||
|
|
||||||
|
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 paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
// ...
|
||||||
|
const RemotePagination = ({ data, page, sizePerPage, onTableChange, totalSize }) => (
|
||||||
|
<div>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={
|
||||||
|
paginationFactory({
|
||||||
|
custom: true,
|
||||||
|
page,
|
||||||
|
sizePerPage,
|
||||||
|
totalSize
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
({
|
||||||
|
paginationProps,
|
||||||
|
paginationTableProps
|
||||||
|
}) => (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<p>Current Page: { paginationProps.page }</p>
|
||||||
|
<p>Current SizePerPage: { paginationProps.sizePerPage }</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<PaginationListStandalone
|
||||||
|
{ ...paginationProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<BootstrapTable
|
||||||
|
remote
|
||||||
|
keyField="id"
|
||||||
|
data={ data }
|
||||||
|
columns={ columns }
|
||||||
|
onTableChange={ onTableChange }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</PaginationProvider>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
class Container extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
page: 1,
|
||||||
|
data: products.slice(0, 10),
|
||||||
|
sizePerPage: 10
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleTableChange = (type, { page, sizePerPage }) => {
|
||||||
|
const currentIndex = (page - 1) * sizePerPage;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState(() => ({
|
||||||
|
page,
|
||||||
|
data: products.slice(currentIndex, currentIndex + sizePerPage),
|
||||||
|
sizePerPage
|
||||||
|
}));
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { data, sizePerPage, page } = this.state;
|
||||||
|
return (
|
||||||
|
<RemotePagination
|
||||||
|
data={ data }
|
||||||
|
page={ page }
|
||||||
|
sizePerPage={ sizePerPage }
|
||||||
|
totalSize={ products.length }
|
||||||
|
onTableChange={ this.handleTableChange }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const RemotePagination = ({ data, page, sizePerPage, onTableChange, totalSize }) => (
|
||||||
|
<div>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={
|
||||||
|
paginationFactory({
|
||||||
|
custom: true,
|
||||||
|
page,
|
||||||
|
sizePerPage,
|
||||||
|
totalSize
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
({
|
||||||
|
paginationProps,
|
||||||
|
paginationTableProps
|
||||||
|
}) => (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<p>Current Page: { paginationProps.page }</p>
|
||||||
|
<p>Current SizePerPage: { paginationProps.sizePerPage }</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<PaginationListStandalone
|
||||||
|
{ ...paginationProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<BootstrapTable
|
||||||
|
remote
|
||||||
|
keyField="id"
|
||||||
|
data={ data }
|
||||||
|
columns={ columns }
|
||||||
|
onTableChange={ onTableChange }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</PaginationProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
RemotePagination.propTypes = {
|
||||||
|
data: PropTypes.array.isRequired,
|
||||||
|
page: PropTypes.number.isRequired,
|
||||||
|
totalSize: PropTypes.number.isRequired,
|
||||||
|
sizePerPage: PropTypes.number.isRequired,
|
||||||
|
onTableChange: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
class Container extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
page: 1,
|
||||||
|
data: products.slice(0, 10),
|
||||||
|
sizePerPage: 10
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleTableChange = (type, { page, sizePerPage }) => {
|
||||||
|
const currentIndex = (page - 1) * sizePerPage;
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState(() => ({
|
||||||
|
page,
|
||||||
|
data: products.slice(currentIndex, currentIndex + sizePerPage),
|
||||||
|
sizePerPage
|
||||||
|
}));
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { data, sizePerPage, page } = this.state;
|
||||||
|
return (
|
||||||
|
<RemotePagination
|
||||||
|
data={ data }
|
||||||
|
page={ page }
|
||||||
|
sizePerPage={ sizePerPage }
|
||||||
|
totalSize={ products.length }
|
||||||
|
onTableChange={ this.handleTableChange }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Container;
|
||||||
107
packages/react-bootstrap-table2-example/examples/pagination/standalone-pagination-total.js
vendored
Normal file
107
packages/react-bootstrap-table2-example/examples/pagination/standalone-pagination-total.js
vendored
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/* eslint react/prefer-stateless-function: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory, { PaginationProvider, PaginationTotalStandalone, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(87);
|
||||||
|
|
||||||
|
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 paginationFactory, { PaginationProvider, PaginationTotalStandalone, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
custom: true,
|
||||||
|
totalSize: products.length
|
||||||
|
};
|
||||||
|
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={ paginationFactory(options) }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
({
|
||||||
|
paginationProps,
|
||||||
|
paginationTableProps
|
||||||
|
}) => (
|
||||||
|
<div>
|
||||||
|
<PaginationTotalStandalone
|
||||||
|
{ ...paginationProps }
|
||||||
|
/>
|
||||||
|
<PaginationListStandalone
|
||||||
|
{ ...paginationProps }
|
||||||
|
/>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</PaginationProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
custom: true,
|
||||||
|
totalSize: products.length
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class StandalonePaginationList extends React.Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<PaginationProvider
|
||||||
|
pagination={ paginationFactory(options) }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
({
|
||||||
|
paginationProps,
|
||||||
|
paginationTableProps
|
||||||
|
}) => (
|
||||||
|
<div>
|
||||||
|
<PaginationTotalStandalone
|
||||||
|
{ ...paginationProps }
|
||||||
|
/>
|
||||||
|
<PaginationListStandalone
|
||||||
|
{ ...paginationProps }
|
||||||
|
/>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
{ ...paginationTableProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</PaginationProvider>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,7 @@ export default class StandaloneSizePerPage extends React.Component {
|
|||||||
<div>
|
<div>
|
||||||
<SizePerPageDropdownStandalone
|
<SizePerPageDropdownStandalone
|
||||||
{ ...paginationProps }
|
{ ...paginationProps }
|
||||||
|
btnContextual="btn btn-primary"
|
||||||
/>
|
/>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
keyField="id"
|
keyField="id"
|
||||||
|
|||||||
76
packages/react-bootstrap-table2-example/examples/row-expand/expand-column-position.js
vendored
Normal file
76
packages/react-bootstrap-table2-example/examples/row-expand/expand-column-position.js
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
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 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'
|
||||||
|
};
|
||||||
|
|
||||||
|
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 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'
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -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>
|
||||||
|
);
|
||||||
86
packages/react-bootstrap-table2-example/examples/search/clear-search-button.js
vendored
Normal file
86
packages/react-bootstrap-table2-example/examples/search/clear-search-button.js
vendored
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/* 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, ClearSearchButton } = 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, ClearSearchButton } = Search;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<h3>Input something at below input field:</h3>
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<ClearSearchButton { ...props.searchProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<ToolkitProvider
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
search
|
||||||
|
>
|
||||||
|
{
|
||||||
|
props => (
|
||||||
|
<div>
|
||||||
|
<h3>Input something at below input field:</h3>
|
||||||
|
<SearchBar { ...props.searchProps } />
|
||||||
|
<ClearSearchButton { ...props.searchProps } />
|
||||||
|
<hr />
|
||||||
|
<BootstrapTable
|
||||||
|
{ ...props.baseProps }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</ToolkitProvider>
|
||||||
|
<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.13",
|
"version": "1.0.36",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -29,10 +29,15 @@ export const withOnSale = rows => rows.map((row) => {
|
|||||||
return row;
|
return row;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const productsQualityGenerator = (quantity = 5) =>
|
export const withRandomPrice = rows => rows.map((row) => {
|
||||||
|
row.price = Math.floor((Math.random() * 10) + 2000);
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
|
||||||
|
export const productsQualityGenerator = (quantity = 5, factor = 0) =>
|
||||||
Array.from({ length: quantity }, (value, index) => ({
|
Array.from({ length: quantity }, (value, index) => ({
|
||||||
id: index,
|
id: index + factor,
|
||||||
name: `Item name ${index}`,
|
name: `Item name ${index + factor}`,
|
||||||
quality: index % 3
|
quality: index % 3
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -69,7 +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),
|
||||||
|
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,8 +18,11 @@ 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 ToolkitsTable from 'examples/bootstrap4/toolkits';
|
||||||
|
|
||||||
// work on columns
|
// work on columns
|
||||||
import NestedDataTable from 'examples/columns/nested-data-table';
|
import NestedDataTable from 'examples/columns/nested-data-table';
|
||||||
@@ -33,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';
|
||||||
@@ -45,6 +49,18 @@ import HeaderColumnStyleTable from 'examples/header-columns/column-style-table';
|
|||||||
import HeaderColumnAttrsTable from 'examples/header-columns/column-attrs-table';
|
import HeaderColumnAttrsTable from 'examples/header-columns/column-attrs-table';
|
||||||
import HeaderClassTable from 'examples/header-columns/header-class-table';
|
import HeaderClassTable from 'examples/header-columns/header-class-table';
|
||||||
|
|
||||||
|
// footer
|
||||||
|
import SimpleFooter from 'examples/footer/simple-footer';
|
||||||
|
import FunctionFooter from 'examples/footer/function-footer';
|
||||||
|
import FooterClassTable from 'examples/footer/footer-class-table';
|
||||||
|
import FooterColumnFormatTable from 'examples/footer/column-format-table';
|
||||||
|
import FooterColumnAlignTable from 'examples/footer/column-align-table';
|
||||||
|
import FooterColumnTitleTable from 'examples/footer/column-title-table.js';
|
||||||
|
import FooterColumnEventsTable from 'examples/footer/column-event-table.js';
|
||||||
|
import FooterColumnClassTable from 'examples/footer/column-class-table.js';
|
||||||
|
import FooterColumnStyleTable from 'examples/footer/column-style-table.js';
|
||||||
|
import FooterColumnAttrsTable from 'examples/footer/column-attrs-table.js';
|
||||||
|
|
||||||
// column filter
|
// column filter
|
||||||
import TextFilter from 'examples/column-filter/text-filter';
|
import TextFilter from 'examples/column-filter/text-filter';
|
||||||
import TextFilterWithDefaultValue from 'examples/column-filter/text-filter-default-value';
|
import TextFilterWithDefaultValue from 'examples/column-filter/text-filter-default-value';
|
||||||
@@ -53,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';
|
||||||
@@ -74,6 +91,9 @@ import ProgrammaticallyMultiSelectFilter from 'examples/column-filter/programmat
|
|||||||
import CustomFilter from 'examples/column-filter/custom-filter';
|
import CustomFilter from 'examples/column-filter/custom-filter';
|
||||||
import AdvanceCustomFilter from 'examples/column-filter/advance-custom-filter';
|
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 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';
|
||||||
@@ -86,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';
|
||||||
@@ -109,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';
|
||||||
@@ -126,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';
|
||||||
@@ -141,11 +171,15 @@ import ExpandColumn from 'examples/row-expand/expand-column';
|
|||||||
import OnlyExpandByColumn from 'examples/row-expand/expand-by-column-only.js';
|
import OnlyExpandByColumn from 'examples/row-expand/expand-by-column-only.js';
|
||||||
import ExpandOnlyOne from 'examples/row-expand/expand-only-one';
|
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 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';
|
||||||
import PaginationHooksTable from 'examples/pagination/pagination-hooks';
|
import PaginationHooksTable from 'examples/pagination/pagination-hooks';
|
||||||
|
import PaginationWithDynamicData from 'examples/pagination/pagination-with-dynamic-data';
|
||||||
import CustomPaginationTable from 'examples/pagination/custom-pagination';
|
import CustomPaginationTable from 'examples/pagination/custom-pagination';
|
||||||
import CustomPageButtonTable from 'examples/pagination/custom-page-button';
|
import CustomPageButtonTable from 'examples/pagination/custom-page-button';
|
||||||
import CustomSizePerPageOptionTable from 'examples/pagination/custom-size-per-page-option';
|
import CustomSizePerPageOptionTable from 'examples/pagination/custom-size-per-page-option';
|
||||||
@@ -153,15 +187,22 @@ import CustomSizePerPageTable from 'examples/pagination/custom-size-per-page';
|
|||||||
import CustomPageListTable from 'examples/pagination/custom-page-list';
|
import CustomPageListTable from 'examples/pagination/custom-page-list';
|
||||||
import StandalonePaginationList from 'examples/pagination/standalone-pagination-list';
|
import StandalonePaginationList from 'examples/pagination/standalone-pagination-list';
|
||||||
import StandaloneSizePerPage from 'examples/pagination/standalone-size-per-page';
|
import StandaloneSizePerPage from 'examples/pagination/standalone-size-per-page';
|
||||||
|
import StandalonePaginationTotal from 'examples/pagination/standalone-pagination-total';
|
||||||
import FullyCustomPaginationTable from 'examples/pagination/fully-custom-pagination';
|
import FullyCustomPaginationTable from 'examples/pagination/fully-custom-pagination';
|
||||||
|
import RemoteStandalonePaginationTable from 'examples/pagination/remote-standalone-pagination';
|
||||||
|
import CustomePaginationWithFilter from 'examples/pagination/custome-page-list-with-filter';
|
||||||
|
import CustomePaginationWithSearch from 'examples/pagination/custom-page-list-with-search';
|
||||||
|
|
||||||
// search
|
// search
|
||||||
import SearchTable from 'examples/search';
|
import SearchTable from 'examples/search';
|
||||||
|
import ClearSearchButton from 'examples/search/clear-search-button';
|
||||||
import DefaultSearch from 'examples/search/default-search';
|
import DefaultSearch from 'examples/search/default-search';
|
||||||
import DefaultCustomSearch from 'examples/search/default-custom-search';
|
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';
|
||||||
@@ -169,10 +210,19 @@ import CSVFormatter from 'examples/csv/csv-column-formatter';
|
|||||||
import CustomCSVHeader from 'examples/csv/custom-csv-header';
|
import CustomCSVHeader from 'examples/csv/custom-csv-header';
|
||||||
import HideCSVColumn from 'examples/csv/hide-column';
|
import HideCSVColumn from 'examples/csv/hide-column';
|
||||||
import ExportOnlySelected from 'examples/csv/export-only-selected';
|
import ExportOnlySelected from 'examples/csv/export-only-selected';
|
||||||
|
import ExportOnlyFiltered from 'examples/csv/export-only-filtered';
|
||||||
import CSVColumnType from 'examples/csv/csv-column-type';
|
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
|
||||||
|
import BasicColumnToggle from 'examples/column-toggle';
|
||||||
|
import DefaultVisibility from 'examples/column-toggle/default-visibility';
|
||||||
|
import StylingColumnToggle from 'examples/column-toggle/styling-toggle-list';
|
||||||
|
import CustomToggleList from 'examples/column-toggle/custom-toggle-list';
|
||||||
|
import ColumnToggleWithFilter from 'examples/column-toggle/column-toggle-with-filter';
|
||||||
|
|
||||||
// loading overlay
|
// loading overlay
|
||||||
import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay';
|
import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay';
|
||||||
@@ -186,18 +236,26 @@ import RemoteSearch from 'examples/remote/remote-search';
|
|||||||
import RemoteCellEdit from 'examples/remote/remote-celledit';
|
import RemoteCellEdit from 'examples/remote/remote-celledit';
|
||||||
import RemoteAll from 'examples/remote/remote-all';
|
import RemoteAll from 'examples/remote/remote-all';
|
||||||
|
|
||||||
|
// data
|
||||||
|
import DataChangeListener from 'examples/data/data-change-listener';
|
||||||
|
import LoadDataWithFilter from 'examples/data/load-data-on-the-fly-with-filter';
|
||||||
|
import LoadDataWithDefaultFilter from 'examples/data/load-data-on-the-fly-with-default-filter';
|
||||||
|
import LoadDataWithSearch from 'examples/data/load-data-on-the-fly-with-search';
|
||||||
|
import LoadDataWithDefaultSearch from 'examples/data/load-data-on-the-fly-with-default-search';
|
||||||
|
import LoadDataWithPaginationAndFilter from 'examples/data/load-data-on-the-fly-with-pagination-and-filter';
|
||||||
|
|
||||||
// css style
|
// css style
|
||||||
import 'stories/stylesheet/tomorrow.min.css';
|
import 'stories/stylesheet/tomorrow.min.css';
|
||||||
import 'stories/stylesheet/storybook.scss';
|
import 'stories/stylesheet/storybook.scss';
|
||||||
import '../../react-bootstrap-table2/style/react-bootstrap-table2.scss';
|
import '../../react-bootstrap-table2/style/react-bootstrap-table2.scss';
|
||||||
import '../../react-bootstrap-table2-paginator/style/react-bootstrap-table2-paginator.scss';
|
import '../../react-bootstrap-table2-paginator/style/react-bootstrap-table2-paginator.scss';
|
||||||
import '../../react-bootstrap-table2-filter/style/react-bootstrap-table2-filter.scss';
|
import '../../react-bootstrap-table2-filter/style/react-bootstrap-table2-filter.scss';
|
||||||
|
import '../../react-bootstrap-table2-toolkit/style/react-bootstrap-table2-toolkit.scss';
|
||||||
|
|
||||||
// import bootstrap style by given version
|
// import bootstrap style by given version
|
||||||
import bootstrapStyle, { BOOTSTRAP_VERSION } from './bootstrap-style';
|
import bootstrapStyle, { BOOTSTRAP_VERSION } from './bootstrap-style';
|
||||||
|
|
||||||
storiesOf('Welcome', module)
|
storiesOf('Welcome', module).add('react bootstrap table 2 ', () => <Welcome />);
|
||||||
.add('react bootstrap table 2 ', () => <Welcome />);
|
|
||||||
|
|
||||||
storiesOf('Basic Table', module)
|
storiesOf('Basic Table', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -214,8 +272,11 @@ 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('toolkits Table bootstrap 4', () => <ToolkitsTable />);
|
||||||
|
|
||||||
storiesOf('Work on Columns', module)
|
storiesOf('Work on Columns', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -229,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())
|
||||||
@@ -251,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 />)
|
||||||
@@ -259,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 />)
|
||||||
@@ -273,7 +337,9 @@ storiesOf('Column Filter', module)
|
|||||||
.add('Custom Filter', () => <CustomFilter />)
|
.add('Custom Filter', () => <CustomFilter />)
|
||||||
.add('Advance Custom Filter', () => <AdvanceCustomFilter />)
|
.add('Advance Custom Filter', () => <AdvanceCustomFilter />)
|
||||||
.add('Preserved Option Order on Select Filter', () => <SelectFilterWithPreservedOptionsOrder />)
|
.add('Preserved Option Order on Select Filter', () => <SelectFilterWithPreservedOptionsOrder />)
|
||||||
.add('Clear All Filters', () => <ClearAllFilters />);
|
.add('Clear All Filters', () => <ClearAllFilters />)
|
||||||
|
.add('Filter Hooks', () => <FilterHooks />)
|
||||||
|
.add('Implement custom filter logic', () => <CustomFilterLogic />);
|
||||||
|
|
||||||
storiesOf('Work on Rows', module)
|
storiesOf('Work on Rows', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -282,12 +348,28 @@ storiesOf('Work on Rows', module)
|
|||||||
.add('Hide Rows', () => <RowHiddenTable />)
|
.add('Hide Rows', () => <RowHiddenTable />)
|
||||||
.add('Row Event', () => <RowEventTable />);
|
.add('Row Event', () => <RowEventTable />);
|
||||||
|
|
||||||
|
storiesOf('Footer', module)
|
||||||
|
.addDecorator(bootstrapStyle())
|
||||||
|
.add('Simple Footer', () => <SimpleFooter />)
|
||||||
|
.add('Function Footer', () => <FunctionFooter />)
|
||||||
|
.add('Column Formatter', () => <FooterColumnFormatTable />)
|
||||||
|
.add('Column Align', () => <FooterColumnAlignTable />)
|
||||||
|
.add('Column Title', () => <FooterColumnTitleTable />)
|
||||||
|
.add('Column Events', () => <FooterColumnEventsTable />)
|
||||||
|
.add('Customize Column Class', () => <FooterColumnClassTable />)
|
||||||
|
.add('Customize Column Style', () => <FooterColumnStyleTable />)
|
||||||
|
.add('Customize Column HTML attribute', () => <FooterColumnAttrsTable />)
|
||||||
|
.add('Footer Class', () => <FooterClassTable />);
|
||||||
|
|
||||||
storiesOf('Sort Table', module)
|
storiesOf('Sort Table', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
.add('Enable Sort', () => <EnableSortTable />)
|
.add('Enable Sort', () => <EnableSortTable />)
|
||||||
.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 />)
|
||||||
@@ -312,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())
|
||||||
@@ -330,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())
|
||||||
@@ -346,12 +435,16 @@ storiesOf('Row Expand', module)
|
|||||||
.add('Only Expand by Indicator', () => <OnlyExpandByColumn />)
|
.add('Only Expand by Indicator', () => <OnlyExpandByColumn />)
|
||||||
.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 Hooks', () => <ExpandHooks />);
|
.add('Expand Column Position', () => <ExpandColumnPosition />)
|
||||||
|
.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())
|
||||||
.add('Basic Pagination Table', () => <PaginationTable />)
|
.add('Basic Pagination Table', () => <PaginationTable />)
|
||||||
.add('Pagination Hooks', () => <PaginationHooksTable />)
|
.add('Pagination Hooks', () => <PaginationHooksTable />)
|
||||||
|
.add('Pagination with Dynamic Data', () => <PaginationWithDynamicData />)
|
||||||
.add('Custom Pagination', () => <CustomPaginationTable />)
|
.add('Custom Pagination', () => <CustomPaginationTable />)
|
||||||
.add('Custom Page Button', () => <CustomPageButtonTable />)
|
.add('Custom Page Button', () => <CustomPageButtonTable />)
|
||||||
.add('Custom Page List', () => <CustomPageListTable />)
|
.add('Custom Page List', () => <CustomPageListTable />)
|
||||||
@@ -359,16 +452,31 @@ storiesOf('Pagination', module)
|
|||||||
.add('Custom SizePerPage', () => <CustomSizePerPageTable />)
|
.add('Custom SizePerPage', () => <CustomSizePerPageTable />)
|
||||||
.add('Standalone Pagination List', () => <StandalonePaginationList />)
|
.add('Standalone Pagination List', () => <StandalonePaginationList />)
|
||||||
.add('Standalone SizePerPage Dropdown', () => <StandaloneSizePerPage />)
|
.add('Standalone SizePerPage Dropdown', () => <StandaloneSizePerPage />)
|
||||||
.add('Fully Custom Pagination', () => <FullyCustomPaginationTable />);
|
.add('Standalone Pagination Total', () => <StandalonePaginationTotal />)
|
||||||
|
.add('Fully Custom Pagination', () => <FullyCustomPaginationTable />)
|
||||||
|
.add('Remote Fully Custom Pagination', () => <RemoteStandalonePaginationTable />)
|
||||||
|
.add('Custom Pagination with Filter', () => <CustomePaginationWithFilter />)
|
||||||
|
.add('Custom Pagination with Search', () => <CustomePaginationWithSearch />);
|
||||||
|
|
||||||
storiesOf('Table Search', module)
|
storiesOf('Table Search', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
.add('Basic Search Table', () => <SearchTable />)
|
.add('Basic Search Table', () => <SearchTable />)
|
||||||
|
.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)
|
||||||
|
.addDecorator(bootstrapStyle())
|
||||||
|
.add('Basic Column Toggle', () => <BasicColumnToggle />)
|
||||||
|
.add('Default Visibility', () => <DefaultVisibility />)
|
||||||
|
.add('Styling Column Toggle', () => <StylingColumnToggle />)
|
||||||
|
.add('Custom Column Toggle', () => <CustomToggleList />)
|
||||||
|
.add('Column Toggle with Filter', () => <ColumnToggleWithFilter />);
|
||||||
|
|
||||||
storiesOf('Export CSV', module)
|
storiesOf('Export CSV', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
@@ -377,10 +485,12 @@ storiesOf('Export CSV', module)
|
|||||||
.add('Custom CSV Header', () => <CustomCSVHeader />)
|
.add('Custom CSV Header', () => <CustomCSVHeader />)
|
||||||
.add('Hide CSV Column', () => <HideCSVColumn />)
|
.add('Hide CSV Column', () => <HideCSVColumn />)
|
||||||
.add('Only Export Selected Rows', () => <ExportOnlySelected />)
|
.add('Only Export Selected Rows', () => <ExportOnlySelected />)
|
||||||
|
.add('Only Export Filtered/Searched Rows', () => <ExportOnlyFiltered />)
|
||||||
.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())
|
||||||
@@ -395,3 +505,12 @@ storiesOf('Remote', module)
|
|||||||
.add('Remote Search', () => <RemoteSearch />)
|
.add('Remote Search', () => <RemoteSearch />)
|
||||||
.add('Remote Cell Editing', () => <RemoteCellEdit />)
|
.add('Remote Cell Editing', () => <RemoteCellEdit />)
|
||||||
.add('Remote All', () => <RemoteAll />);
|
.add('Remote All', () => <RemoteAll />);
|
||||||
|
|
||||||
|
storiesOf('Data', module)
|
||||||
|
.addDecorator(bootstrapStyle())
|
||||||
|
.add('Data Change Listener', () => <DataChangeListener />)
|
||||||
|
.add('Load data with Filter', () => <LoadDataWithFilter />)
|
||||||
|
.add('Load data with Default Filter', () => <LoadDataWithDefaultFilter />)
|
||||||
|
.add('Load data with Search', () => <LoadDataWithSearch />)
|
||||||
|
.add('Load data with Default Search', () => <LoadDataWithDefaultSearch />)
|
||||||
|
.add('Load data with Filter and Pagination', () => <LoadDataWithPaginationAndFilter />);
|
||||||
|
|||||||
@@ -14,3 +14,7 @@
|
|||||||
.header-class {
|
.header-class {
|
||||||
background-color: $green-lighten-4;
|
background-color: $green-lighten-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.footer-class {
|
||||||
|
background-color: $green-lighten-4;
|
||||||
|
}
|
||||||
@@ -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.0",
|
"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": {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const legalComparators = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function dateParser(d) {
|
function dateParser(d) {
|
||||||
return `${d.getFullYear()}-${('0' + (d.getMonth() + 1)).slice(-2)}-${('0' + d.getDate()).slice(-2)}`;
|
return `${d.getUTCFullYear()}-${('0' + (d.getUTCMonth() + 1)).slice(-2)}-${('0' + d.getUTCDate()).slice(-2)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DateFilter extends Component {
|
class DateFilter extends Component {
|
||||||
@@ -42,10 +42,11 @@ class DateFilter extends Component {
|
|||||||
// export onFilter function to allow users to access
|
// export onFilter function to allow users to access
|
||||||
if (getFilter) {
|
if (getFilter) {
|
||||||
getFilter((filterVal) => {
|
getFilter((filterVal) => {
|
||||||
this.dateFilterComparator.value = filterVal.comparator;
|
const nullableFilterVal = filterVal || { date: null, comparator: null };
|
||||||
this.inputDate.value = dateParser(filterVal.date);
|
this.dateFilterComparator.value = nullableFilterVal.comparator;
|
||||||
|
this.inputDate.value = nullableFilterVal.date ? dateParser(nullableFilterVal.date) : null;
|
||||||
|
|
||||||
this.applyFilter(filterVal.date, filterVal.comparator);
|
this.applyFilter(nullableFilterVal.date, nullableFilterVal.comparator);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,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) {
|
||||||
@@ -121,8 +135,7 @@ class DateFilter extends Component {
|
|||||||
dateStyle,
|
dateStyle,
|
||||||
className,
|
className,
|
||||||
comparatorClassName,
|
comparatorClassName,
|
||||||
dateClassName,
|
dateClassName
|
||||||
defaultValue
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -131,17 +144,27 @@ class DateFilter extends Component {
|
|||||||
className={ `filter date-filter ${className}` }
|
className={ `filter date-filter ${className}` }
|
||||||
style={ style }
|
style={ style }
|
||||||
>
|
>
|
||||||
|
<label
|
||||||
|
className="filter-label"
|
||||||
|
htmlFor={ `date-filter-comparator-${text}` }
|
||||||
|
>
|
||||||
|
<span className="sr-only">Filter comparator</span>
|
||||||
<select
|
<select
|
||||||
ref={ n => this.dateFilterComparator = n }
|
ref={ n => this.dateFilterComparator = n }
|
||||||
|
id={ `date-filter-comparator-${text}` }
|
||||||
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>
|
||||||
|
</label>
|
||||||
|
<label htmlFor={ `date-filter-column-${text}` }>
|
||||||
|
<span className="sr-only">Enter ${ text }</span>
|
||||||
<input
|
<input
|
||||||
ref={ n => this.inputDate = n }
|
ref={ n => this.inputDate = n }
|
||||||
|
id={ `date-filter-column-${text}` }
|
||||||
className={ `filter date-filter-input form-control ${dateClassName}` }
|
className={ `filter date-filter-input form-control ${dateClassName}` }
|
||||||
style={ dateStyle }
|
style={ dateStyle }
|
||||||
type="date"
|
type="date"
|
||||||
@@ -149,6 +172,7 @@ class DateFilter extends Component {
|
|||||||
placeholder={ placeholder || `Enter ${text}...` }
|
placeholder={ placeholder || `Enter ${text}...` }
|
||||||
defaultValue={ this.getDefaultDate() }
|
defaultValue={ this.getDefaultDate() }
|
||||||
/>
|
/>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -157,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]),
|
||||||
@@ -198,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,
|
||||||
@@ -111,18 +130,25 @@ class MultiSelectFilter extends Component {
|
|||||||
`filter select-filter form-control ${className} ${this.state.isSelected ? '' : 'placeholder-selected'}`;
|
`filter select-filter form-control ${className} ${this.state.isSelected ? '' : 'placeholder-selected'}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<label
|
||||||
|
className="filter-label"
|
||||||
|
htmlFor={ `multiselect-filter-column-${column.text}` }
|
||||||
|
>
|
||||||
|
<span className="sr-only">Filter by {column.text}</span>
|
||||||
<select
|
<select
|
||||||
{ ...rest }
|
{ ...rest }
|
||||||
ref={ n => this.selectInput = n }
|
ref={ n => this.selectInput = n }
|
||||||
|
id={ `multiselect-filter-column-${column.text}` }
|
||||||
style={ style }
|
style={ style }
|
||||||
multiple
|
multiple
|
||||||
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>
|
||||||
|
</label>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,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,
|
||||||
@@ -143,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,
|
||||||
@@ -173,35 +194,53 @@ class NumberFilter extends Component {
|
|||||||
className={ `filter number-filter ${className}` }
|
className={ `filter number-filter ${className}` }
|
||||||
style={ style }
|
style={ style }
|
||||||
>
|
>
|
||||||
|
<label
|
||||||
|
className="filter-label"
|
||||||
|
htmlFor={ `number-filter-comparator-${column.text}` }
|
||||||
|
>
|
||||||
|
<span className="sr-only">Filter comparator</span>
|
||||||
<select
|
<select
|
||||||
ref={ n => this.numberFilterComparator = n }
|
ref={ n => this.numberFilterComparator = n }
|
||||||
style={ comparatorStyle }
|
style={ comparatorStyle }
|
||||||
|
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>
|
||||||
|
</label>
|
||||||
{
|
{
|
||||||
options ?
|
options ?
|
||||||
|
<label
|
||||||
|
className="filter-label"
|
||||||
|
htmlFor={ `number-filter-column-${column.text}` }
|
||||||
|
>
|
||||||
|
<span className="sr-only">{`Select ${column.text}`}</span>
|
||||||
<select
|
<select
|
||||||
ref={ n => this.numberFilter = n }
|
ref={ n => this.numberFilter = n }
|
||||||
|
id={ `number-filter-column-${column.text}` }
|
||||||
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>
|
||||||
|
</label> :
|
||||||
|
<label htmlFor={ `number-filter-column-${column.text}` }>
|
||||||
|
<span className="sr-only">{`Enter ${column.text}`}</span>
|
||||||
<input
|
<input
|
||||||
ref={ n => this.numberFilter = n }
|
ref={ n => this.numberFilter = n }
|
||||||
|
id={ `number-filter-column-${column.text}` }
|
||||||
type="number"
|
type="number"
|
||||||
style={ numberStyle }
|
style={ numberStyle }
|
||||||
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>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -211,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]),
|
||||||
@@ -255,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';
|
||||||
@@ -8,6 +9,7 @@ import { FILTER_TYPE } from '../const';
|
|||||||
|
|
||||||
function optionsEquals(currOpts, prevOpts) {
|
function optionsEquals(currOpts, prevOpts) {
|
||||||
if (Array.isArray(currOpts)) {
|
if (Array.isArray(currOpts)) {
|
||||||
|
if (currOpts.length === prevOpts.length) {
|
||||||
for (let i = 0; i < currOpts.length; i += 1) {
|
for (let i = 0; i < currOpts.length; i += 1) {
|
||||||
if (
|
if (
|
||||||
currOpts[i].value !== prevOpts[i].value ||
|
currOpts[i].value !== prevOpts[i].value ||
|
||||||
@@ -16,7 +18,9 @@ function optionsEquals(currOpts, prevOpts) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return currOpts.length === prevOpts.length;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
const keys = Object.keys(currOpts);
|
const keys = Object.keys(currOpts);
|
||||||
for (let i = 0; i < keys.length; i += 1) {
|
for (let i = 0; i < keys.length; i += 1) {
|
||||||
@@ -41,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 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,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((
|
|
||||||
<option key="-1" value="">{ placeholder || `Select ${column.text}...` }</option>
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if (Array.isArray(options)) {
|
|
||||||
options.forEach(({ value, label }) =>
|
getDefaultValue() {
|
||||||
optionTags.push(<option key={ value } value={ value }>{ label }</option>));
|
const { filterState, defaultValue } = this.props;
|
||||||
} else {
|
if (filterState && typeof filterState.filterVal !== 'undefined') {
|
||||||
Object.keys(options).forEach(key =>
|
return filterState.filterVal;
|
||||||
optionTags.push(<option key={ key } value={ key }>{ options[key] }</option>)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return optionTags;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanFiltered() {
|
cleanFiltered() {
|
||||||
@@ -117,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,
|
||||||
@@ -129,6 +154,7 @@ class SelectFilter extends Component {
|
|||||||
withoutEmptyOption,
|
withoutEmptyOption,
|
||||||
caseSensitive,
|
caseSensitive,
|
||||||
getFilter,
|
getFilter,
|
||||||
|
filterState,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -136,17 +162,24 @@ class SelectFilter extends Component {
|
|||||||
`filter select-filter form-control ${className} ${this.state.isSelected ? '' : 'placeholder-selected'}`;
|
`filter select-filter form-control ${className} ${this.state.isSelected ? '' : 'placeholder-selected'}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<label
|
||||||
|
className="filter-label"
|
||||||
|
htmlFor={ `select-filter-column-${column.text}` }
|
||||||
|
>
|
||||||
|
<span className="sr-only">Filter by { column.text }</span>
|
||||||
<select
|
<select
|
||||||
{ ...rest }
|
{ ...rest }
|
||||||
ref={ n => this.selectInput = n }
|
ref={ n => this.selectInput = n }
|
||||||
|
id={ `select-filter-column-${column.text}` }
|
||||||
style={ style }
|
style={ style }
|
||||||
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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,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,
|
||||||
@@ -167,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,15 +96,22 @@ class TextFilter extends Component {
|
|||||||
caseSensitive,
|
caseSensitive,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
getFilter,
|
getFilter,
|
||||||
|
filterState,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
// stopPropagation for onClick event is try to prevent sort was triggered.
|
// stopPropagation for onClick event is try to prevent sort was triggered.
|
||||||
return (
|
return (
|
||||||
|
<label
|
||||||
|
className="filter-label"
|
||||||
|
htmlFor={ `text-filter-column-${text}` }
|
||||||
|
>
|
||||||
|
<span className="sr-only">Filter by {text}</span>
|
||||||
<input
|
<input
|
||||||
{ ...rest }
|
{ ...rest }
|
||||||
ref={ n => this.input = n }
|
ref={ n => this.input = n }
|
||||||
type="text"
|
type="text"
|
||||||
|
id={ `text-filter-column-${text}` }
|
||||||
className={ `filter text-filter form-control ${className}` }
|
className={ `filter text-filter form-control ${className}` }
|
||||||
style={ style }
|
style={ style }
|
||||||
onChange={ this.filter }
|
onChange={ this.filter }
|
||||||
@@ -105,6 +119,7 @@ class TextFilter extends Component {
|
|||||||
placeholder={ placeholder || `Enter ${text}...` }
|
placeholder={ placeholder || `Enter ${text}...` }
|
||||||
value={ this.state.value }
|
value={ this.state.value }
|
||||||
/>
|
/>
|
||||||
|
</label>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,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,
|
||||||
@@ -124,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';
|
||||||
|
|
||||||
@@ -17,14 +18,18 @@ export default (
|
|||||||
class FilterProvider extends React.Component {
|
class FilterProvider extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
data: PropTypes.array.isRequired,
|
data: PropTypes.array.isRequired,
|
||||||
columns: PropTypes.array.isRequired
|
columns: PropTypes.array.isRequired,
|
||||||
|
dataChangeListener: PropTypes.object
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.currFilters = {};
|
this.currFilters = {};
|
||||||
this.onFilter = this.onFilter.bind(this);
|
this.onFilter = this.onFilter.bind(this);
|
||||||
|
this.doFilter = this.doFilter.bind(this);
|
||||||
this.onExternalFilter = this.onExternalFilter.bind(this);
|
this.onExternalFilter = this.onExternalFilter.bind(this);
|
||||||
|
this.data = props.data;
|
||||||
|
this.isEmitDataChange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -63,8 +68,7 @@ export default (
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.doFilter(this.props);
|
||||||
this.forceUpdate();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,16 +78,39 @@ export default (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
getFiltered() {
|
||||||
let { data } = this.props;
|
return this.data;
|
||||||
if (!isRemoteFiltering()) {
|
|
||||||
data = filters(data, this.props.columns, _)(this.currFilters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
// 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 result = filters(data, columns, _)(this.currFilters);
|
||||||
|
this.data = result;
|
||||||
|
if (dataChangeListener && !ignoreEmitDataChange) {
|
||||||
|
this.isEmitDataChange = true;
|
||||||
|
dataChangeListener.emit('filterChanged', result.length);
|
||||||
|
} else {
|
||||||
|
this.isEmitDataChange = false;
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<FilterContext.Provider value={ {
|
<FilterContext.Provider value={ {
|
||||||
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 }
|
||||||
|
|||||||
@@ -98,9 +98,9 @@ export const filterByDate = _ => (
|
|||||||
customFilterValue
|
customFilterValue
|
||||||
) => {
|
) => {
|
||||||
if (!date || !comparator) return data;
|
if (!date || !comparator) return data;
|
||||||
const filterDate = date.getDate();
|
const filterDate = date.getUTCDate();
|
||||||
const filterMonth = date.getMonth();
|
const filterMonth = date.getUTCMonth();
|
||||||
const filterYear = date.getFullYear();
|
const filterYear = date.getUTCFullYear();
|
||||||
|
|
||||||
return data.filter((row) => {
|
return data.filter((row) => {
|
||||||
let valid = true;
|
let valid = true;
|
||||||
@@ -114,9 +114,9 @@ export const filterByDate = _ => (
|
|||||||
cell = new Date(cell);
|
cell = new Date(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetDate = cell.getDate();
|
const targetDate = cell.getUTCDate();
|
||||||
const targetMonth = cell.getMonth();
|
const targetMonth = cell.getUTCMonth();
|
||||||
const targetYear = cell.getFullYear();
|
const targetYear = cell.getUTCFullYear();
|
||||||
|
|
||||||
|
|
||||||
switch (comparator) {
|
switch (comparator) {
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (customFilter) {
|
||||||
|
currentResult = customFilter(filterObj.filterVal, result);
|
||||||
|
}
|
||||||
|
if (typeof currentResult === 'undefined') {
|
||||||
result = filterFn(result, dataField, filterObj, filterValue);
|
result = filterFn(result, dataField, filterObj, filterValue);
|
||||||
|
} else {
|
||||||
|
result = currentResult;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
.react-bootstrap-table > table > thead > tr > th .filter-label {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
.react-bootstrap-table > table > thead > tr > th .filter {
|
.react-bootstrap-table > table > thead > tr > th .filter {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user