mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 21:50:07 +00:00
Compare commits
41 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -69,7 +69,7 @@ const cellEdit: {
|
||||
// omit...
|
||||
beforeSaveCell(oldValue, newValue, row, column, done) {
|
||||
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
|
||||
} else {
|
||||
done(false); // reject the changes
|
||||
|
||||
@@ -164,7 +164,7 @@ Enable the column sort via a `true` value given.
|
||||
```
|
||||
|
||||
## <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
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Row expand
|
||||
`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
|
||||
* [renderer (**required**)](#renderer)
|
||||
|
||||
@@ -132,7 +132,7 @@ const columns = [
|
||||
if (typeof cell !== 'object') {
|
||||
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: {
|
||||
type: Type.DATE
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-editor",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"description": "it's the editor addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
|
||||
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>
|
||||
);
|
||||
@@ -18,6 +18,11 @@ class QualityRanger extends React.Component {
|
||||
static defaultProps = {
|
||||
value: 0
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.range.focus();
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return parseInt(this.range.value, 10);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ const columns = [{
|
||||
if (typeof cell !== 'object') {
|
||||
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: {
|
||||
type: Type.DATE
|
||||
@@ -48,7 +48,7 @@ const columns = [{
|
||||
if (typeof cell !== 'object') {
|
||||
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: {
|
||||
type: Type.DATE
|
||||
|
||||
@@ -11,141 +11,13 @@ const products = [
|
||||
{ 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 = `\
|
||||
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 {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { products };
|
||||
this.state = { products, count: 0 };
|
||||
}
|
||||
|
||||
toggleInStock = () => {
|
||||
@@ -163,17 +35,96 @@ class ProductList extends React.Component {
|
||||
};
|
||||
|
||||
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 (
|
||||
<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
|
||||
keyField="id"
|
||||
data={ this.state.products }
|
||||
columns={ columns }
|
||||
/>
|
||||
<button onClick={ this.toggleInStock } className="btn btn-primary">
|
||||
Toggle item 13 stock status
|
||||
</button>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -183,7 +134,7 @@ class ProductList extends React.Component {
|
||||
class ProductList extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { products };
|
||||
this.state = { products, count: 0 };
|
||||
}
|
||||
|
||||
toggleInStock = () => {
|
||||
@@ -200,13 +151,95 @@ class ProductList extends React.Component {
|
||||
this.setState(curr => ({ ...curr, products: newProducts }));
|
||||
};
|
||||
|
||||
counter = () => {
|
||||
this.setState(curr => ({ ...curr, count: this.state.count + 1 }));
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<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.counter }
|
||||
>
|
||||
Click me to Increase counter
|
||||
</button>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ this.state.products }
|
||||
|
||||
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>
|
||||
);
|
||||
@@ -7,7 +7,7 @@ import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator(21);
|
||||
const products = productsGenerator(40);
|
||||
const { SearchBar } = Search;
|
||||
|
||||
const columns = [{
|
||||
@@ -24,61 +24,12 @@ import paginationFactory, { PaginationProvider, PaginationListStandalone } from
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
class Table extends React.Component {
|
||||
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: products.length
|
||||
};
|
||||
const contentTable = ({ paginationProps, paginationTableProps }) => (
|
||||
<div>
|
||||
<PaginationListStandalone { ...paginationProps } />
|
||||
<div>
|
||||
<div>
|
||||
<BootstrapTable
|
||||
striped
|
||||
hover
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
cellEdit={ cellEditFactory() }
|
||||
{ ...paginationTableProps }
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<PaginationListStandalone { ...paginationProps } />
|
||||
</div>
|
||||
);
|
||||
state = { products }
|
||||
|
||||
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 >
|
||||
);
|
||||
loadData = () => {
|
||||
this.setState({ products: productsGenerator(17) });
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default class Table extends React.Component {
|
||||
render() {
|
||||
const options = {
|
||||
custom: true,
|
||||
@@ -93,15 +44,84 @@ export default class Table extends React.Component {
|
||||
firstPageTitle: 'Next page',
|
||||
lastPageTitle: 'Last page',
|
||||
showTotal: true,
|
||||
totalSize: products.length
|
||||
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={ products }
|
||||
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
|
||||
>
|
||||
{
|
||||
|
||||
@@ -3,28 +3,70 @@ import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
import filterFactory, { textFilter, selectFilter } from 'react-bootstrap-table2-filter';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
import { productsQualityGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator(21);
|
||||
const products = productsQualityGenerator(21);
|
||||
|
||||
const selectOptions = {
|
||||
0: 'good',
|
||||
1: 'Bad',
|
||||
2: 'unknown'
|
||||
};
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
filter: textFilter({})
|
||||
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 } from 'react-bootstrap-table2-filter';
|
||||
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,
|
||||
@@ -39,10 +81,11 @@ class Table extends React.Component {
|
||||
firstPageTitle: 'Next page',
|
||||
lastPageTitle: 'Last page',
|
||||
showTotal: true,
|
||||
totalSize: products.length
|
||||
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>
|
||||
@@ -50,10 +93,9 @@ class Table extends React.Component {
|
||||
striped
|
||||
hover
|
||||
keyField="id"
|
||||
data={ products }
|
||||
data={ this.state.products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
cellEdit={ cellEditFactory() }
|
||||
{ ...paginationTableProps }
|
||||
/>
|
||||
</div>
|
||||
@@ -72,7 +114,6 @@ class Table extends React.Component {
|
||||
>
|
||||
{ contentTable }
|
||||
</PaginationProvider>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div >
|
||||
);
|
||||
}
|
||||
@@ -80,6 +121,12 @@ class Table extends React.Component {
|
||||
`;
|
||||
|
||||
export default class Table extends React.Component {
|
||||
state = { products }
|
||||
|
||||
loadData = () => {
|
||||
this.setState({ products: productsQualityGenerator(40, 7) });
|
||||
}
|
||||
|
||||
render() {
|
||||
const options = {
|
||||
custom: true,
|
||||
@@ -94,10 +141,11 @@ export default class Table extends React.Component {
|
||||
firstPageTitle: 'Next page',
|
||||
lastPageTitle: 'Last page',
|
||||
showTotal: true,
|
||||
totalSize: products.length
|
||||
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>
|
||||
@@ -105,7 +153,7 @@ export default class Table extends React.Component {
|
||||
striped
|
||||
hover
|
||||
keyField="id"
|
||||
data={ products }
|
||||
data={ this.state.products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
{ ...paginationTableProps }
|
||||
|
||||
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>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ export default class StandaloneSizePerPage extends React.Component {
|
||||
<div>
|
||||
<SizePerPageDropdownStandalone
|
||||
{ ...paginationProps }
|
||||
btnContextual="btn btn-primary"
|
||||
/>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-example",
|
||||
"version": "1.0.18",
|
||||
"version": "1.0.23",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
||||
@@ -29,10 +29,10 @@ export const withOnSale = rows => rows.map((row) => {
|
||||
return row;
|
||||
});
|
||||
|
||||
export const productsQualityGenerator = (quantity = 5) =>
|
||||
export const productsQualityGenerator = (quantity = 5, factor = 0) =>
|
||||
Array.from({ length: quantity }, (value, index) => ({
|
||||
id: index,
|
||||
name: `Item name ${index}`,
|
||||
id: index + factor,
|
||||
name: `Item name ${index + factor}`,
|
||||
quality: index % 3
|
||||
}));
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
||||
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
|
||||
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
|
||||
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
|
||||
import ToolkitsTable from 'examples/bootstrap4/toolkits';
|
||||
|
||||
// work on columns
|
||||
import NestedDataTable from 'examples/columns/nested-data-table';
|
||||
@@ -162,6 +163,7 @@ import ExpandHooks from 'examples/row-expand/expand-hooks';
|
||||
// pagination
|
||||
import PaginationTable from 'examples/pagination';
|
||||
import PaginationHooksTable from 'examples/pagination/pagination-hooks';
|
||||
import PaginationWithDynamicData from 'examples/pagination/pagination-with-dynamic-data';
|
||||
import CustomPaginationTable from 'examples/pagination/custom-pagination';
|
||||
import CustomPageButtonTable from 'examples/pagination/custom-page-button';
|
||||
import CustomSizePerPageOptionTable from 'examples/pagination/custom-size-per-page-option';
|
||||
@@ -190,6 +192,7 @@ import CSVFormatter from 'examples/csv/csv-column-formatter';
|
||||
import CustomCSVHeader from 'examples/csv/custom-csv-header';
|
||||
import HideCSVColumn from 'examples/csv/hide-column';
|
||||
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 CustomCSVButton from 'examples/csv/custom-csv-button';
|
||||
import ExportCustomData from 'examples/csv/export-custom-data';
|
||||
@@ -249,7 +252,8 @@ storiesOf('Bootstrap 4', module)
|
||||
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
|
||||
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
|
||||
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
|
||||
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />);
|
||||
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
|
||||
.add('toolkits Table bootstrap 4', () => <ToolkitsTable />);
|
||||
|
||||
storiesOf('Work on Columns', module)
|
||||
.addDecorator(bootstrapStyle())
|
||||
@@ -402,6 +406,7 @@ storiesOf('Pagination', module)
|
||||
.addDecorator(bootstrapStyle())
|
||||
.add('Basic Pagination Table', () => <PaginationTable />)
|
||||
.add('Pagination Hooks', () => <PaginationHooksTable />)
|
||||
.add('Pagination with Dynamic Data', () => <PaginationWithDynamicData />)
|
||||
.add('Custom Pagination', () => <CustomPaginationTable />)
|
||||
.add('Custom Page Button', () => <CustomPageButtonTable />)
|
||||
.add('Custom Page List', () => <CustomPageListTable />)
|
||||
@@ -439,6 +444,7 @@ storiesOf('Export CSV', module)
|
||||
.add('Custom CSV Header', () => <CustomCSVHeader />)
|
||||
.add('Hide CSV Column', () => <HideCSVColumn />)
|
||||
.add('Only Export Selected Rows', () => <ExportOnlySelected />)
|
||||
.add('Only Export Filtered/Searched Rows', () => <ExportOnlyFiltered />)
|
||||
.add('CSV Column Type', () => <CSVColumnType />)
|
||||
.add('Custom CSV Button', () => <CustomCSVButton />)
|
||||
.add('Export Custom Data', () => <ExportCustomData />)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-filter",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.8",
|
||||
"description": "it's a column filter addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -18,7 +18,7 @@ const legalComparators = [
|
||||
];
|
||||
|
||||
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 {
|
||||
|
||||
@@ -27,9 +27,8 @@ export default (
|
||||
this.onFilter = this.onFilter.bind(this);
|
||||
this.doFilter = this.doFilter.bind(this);
|
||||
this.onExternalFilter = this.onExternalFilter.bind(this);
|
||||
this.state = {
|
||||
data: props.data
|
||||
};
|
||||
this.data = props.data;
|
||||
this.isEmitDataChange = false;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@@ -39,13 +38,12 @@ export default (
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
let nextData = nextProps.data;
|
||||
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.props.data)) {
|
||||
nextData = this.doFilter(nextProps);
|
||||
// let nextData = nextProps.data;
|
||||
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
|
||||
this.doFilter(nextProps, undefined, this.isEmitDataChange);
|
||||
} else {
|
||||
this.data = nextProps.data;
|
||||
}
|
||||
this.setState({
|
||||
data: nextData
|
||||
});
|
||||
}
|
||||
|
||||
onFilter(column, filterType, initialize = false) {
|
||||
@@ -83,9 +81,7 @@ export default (
|
||||
if (filter.props.onFilter) {
|
||||
result = filter.props.onFilter(filterVal);
|
||||
}
|
||||
|
||||
result = this.doFilter(this.props, result);
|
||||
this.setState({ data: result });
|
||||
this.doFilter(this.props, result);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,21 +91,29 @@ export default (
|
||||
};
|
||||
}
|
||||
|
||||
doFilter(props, customResult) {
|
||||
getFiltered() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
doFilter(props, customResult, ignoreEmitDataChange = false) {
|
||||
let result = customResult;
|
||||
|
||||
const { dataChangeListener, data, columns } = props;
|
||||
result = result || filters(data, columns, _)(this.currFilters);
|
||||
if (dataChangeListener) {
|
||||
this.data = result;
|
||||
if (dataChangeListener && !ignoreEmitDataChange) {
|
||||
this.isEmitDataChange = true;
|
||||
dataChangeListener.emit('filterChanged', result.length);
|
||||
} else {
|
||||
this.isEmitDataChange = false;
|
||||
this.forceUpdate();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<FilterContext.Provider value={ {
|
||||
data: this.state.data,
|
||||
data: this.data,
|
||||
onFilter: this.onFilter,
|
||||
onExternalFilter: this.onExternalFilter
|
||||
} }
|
||||
|
||||
@@ -98,9 +98,9 @@ export const filterByDate = _ => (
|
||||
customFilterValue
|
||||
) => {
|
||||
if (!date || !comparator) return data;
|
||||
const filterDate = date.getDate();
|
||||
const filterMonth = date.getMonth();
|
||||
const filterYear = date.getFullYear();
|
||||
const filterDate = date.getUTCDate();
|
||||
const filterMonth = date.getUTCMonth();
|
||||
const filterYear = date.getUTCFullYear();
|
||||
|
||||
return data.filter((row) => {
|
||||
let valid = true;
|
||||
@@ -114,9 +114,9 @@ export const filterByDate = _ => (
|
||||
cell = new Date(cell);
|
||||
}
|
||||
|
||||
const targetDate = cell.getDate();
|
||||
const targetMonth = cell.getMonth();
|
||||
const targetYear = cell.getFullYear();
|
||||
const targetDate = cell.getUTCDate();
|
||||
const targetMonth = cell.getUTCMonth();
|
||||
const targetYear = cell.getUTCFullYear();
|
||||
|
||||
|
||||
switch (comparator) {
|
||||
|
||||
@@ -283,9 +283,9 @@ describe('FilterContext', () => {
|
||||
expect(onFilter).toHaveBeenCalledWith(filterVal);
|
||||
});
|
||||
|
||||
it('should set state.data correctly', () => {
|
||||
it('should set data correctly', () => {
|
||||
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(instance.state.data).toEqual(mockReturn);
|
||||
expect(instance.data).toEqual(mockReturn);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -190,6 +190,19 @@ import paginationFactory, {
|
||||
|
||||
That's it!! The benifit for using standalone is you can much easier to render the standalone component in any posistion. In the future, we will implement more featue like applying `style`, `className` etc on standalone components.
|
||||
|
||||
##### Customizable props for `PaginationListStandalone`
|
||||
* N/A
|
||||
|
||||
##### Customizable props for `SizePerPageDropdownStandalone`
|
||||
* `open`: `true` to make dropdown show.
|
||||
* `hidden`: `true` to hide the size per page dropdown.
|
||||
* `btnContextual`: Set the button contextual
|
||||
* `variation`: Variation for dropdown, available value is `dropdown` and `dropup`.
|
||||
* `className`: Custom the class on size per page dropdown
|
||||
|
||||
##### Customizable props for `SizePerPageDropdownStandalone`
|
||||
* N/A
|
||||
|
||||
#### 4.2 Customization Everything
|
||||
|
||||
If you choose to custom the pagination component by yourself, the `paginationProps` will be important for you. Becasue you have to know for example how to change page or what's the current page etc. Hence, following is all the props in `paginationProps` object:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-paginator",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.5",
|
||||
"description": "it's the pagination addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -32,7 +32,12 @@ class PaginationDataProvider extends Provider {
|
||||
// user should align the page when the page is not fit to the data size when remote enable
|
||||
if (!this.isRemotePagination() && !custom) {
|
||||
const newPage = alignPage(
|
||||
nextProps.data.length, this.currPage, currSizePerPage, pageStartIndex);
|
||||
nextProps.data.length,
|
||||
this.props.data.length,
|
||||
this.currPage,
|
||||
currSizePerPage,
|
||||
pageStartIndex
|
||||
);
|
||||
|
||||
if (this.currPage !== newPage) {
|
||||
if (onPageChange) {
|
||||
|
||||
@@ -56,7 +56,7 @@ export default ExtendBase =>
|
||||
alwaysShowAllBtns
|
||||
} = this.props;
|
||||
|
||||
let pages;
|
||||
let pages = [];
|
||||
let endPage = totalPages;
|
||||
if (endPage <= 0) return [];
|
||||
|
||||
@@ -68,24 +68,42 @@ export default ExtendBase =>
|
||||
startPage = endPage - paginationSize + 1;
|
||||
}
|
||||
|
||||
if (startPage !== pageStartIndex && totalPages > paginationSize && withFirstAndLast) {
|
||||
if (alwaysShowAllBtns) {
|
||||
if (withFirstAndLast) {
|
||||
pages = [firstPageText, prePageText];
|
||||
} else {
|
||||
pages = [prePageText];
|
||||
}
|
||||
}
|
||||
|
||||
if (startPage !== pageStartIndex &&
|
||||
totalPages > paginationSize &&
|
||||
withFirstAndLast &&
|
||||
pages.length === 0
|
||||
) {
|
||||
pages = [firstPageText, prePageText];
|
||||
} else if (totalPages > 1 || alwaysShowAllBtns) {
|
||||
} else if (totalPages > 1 && pages.length === 0) {
|
||||
pages = [prePageText];
|
||||
} else {
|
||||
pages = [];
|
||||
}
|
||||
|
||||
for (let i = startPage; i <= endPage; i += 1) {
|
||||
if (i >= pageStartIndex) pages.push(i);
|
||||
}
|
||||
|
||||
if (endPage <= lastPage && pages.length > 1) {
|
||||
if (alwaysShowAllBtns || (endPage <= lastPage && pages.length > 1)) {
|
||||
pages.push(nextPageText);
|
||||
}
|
||||
if (endPage !== lastPage && withFirstAndLast) {
|
||||
if ((endPage !== lastPage && withFirstAndLast) || (withFirstAndLast && alwaysShowAllBtns)) {
|
||||
pages.push(lastPageText);
|
||||
}
|
||||
|
||||
// if ((endPage <= lastPage && pages.length > 1) || alwaysShowAllBtns) {
|
||||
// pages.push(nextPageText);
|
||||
// }
|
||||
// if (endPage !== lastPage && withFirstAndLast) {
|
||||
// pages.push(lastPageText);
|
||||
// }
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import Const from './const';
|
||||
|
||||
const getNormalizedPage = (
|
||||
page,
|
||||
pageStartIndex
|
||||
@@ -19,12 +21,20 @@ const startIndex = (
|
||||
|
||||
export const alignPage = (
|
||||
dataSize,
|
||||
prevDataSize,
|
||||
page,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
) => {
|
||||
if (page < pageStartIndex || page > (Math.floor(dataSize / sizePerPage) + pageStartIndex)) {
|
||||
return pageStartIndex;
|
||||
if (prevDataSize < dataSize) return page;
|
||||
if (page < pageStartIndex) return pageStartIndex;
|
||||
if (dataSize <= 0) return pageStartIndex;
|
||||
if ((page >= (Math.floor(dataSize / sizePerPage) + pageStartIndex)) && pageStartIndex === 1) {
|
||||
return Math.ceil(dataSize / sizePerPage);
|
||||
}
|
||||
if (page >= Math.floor(dataSize / sizePerPage) && pageStartIndex === 0) {
|
||||
const newPage = Math.ceil(dataSize / sizePerPage);
|
||||
return newPage - Math.abs((Const.PAGE_START_INDEX - pageStartIndex));
|
||||
}
|
||||
return page;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ const sizePerPageDropdownAdapter = WrappedComponent =>
|
||||
}
|
||||
return (
|
||||
<WrappedComponent
|
||||
{ ...this.props }
|
||||
currSizePerPage={ `${currSizePerPage}` }
|
||||
options={ this.calculateSizePerPageStatus() }
|
||||
optionRenderer={ sizePerPageOptionRenderer }
|
||||
|
||||
@@ -50,9 +50,15 @@ class StateProvider extends React.Component {
|
||||
|
||||
// user should align the page when the page is not fit to the data size when remote enable
|
||||
if (this.isRemotePagination() || custom) {
|
||||
this.currPage = nextProps.pagination.options.page;
|
||||
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
|
||||
this.dataSize = nextProps.pagination.options.totalSize;
|
||||
if (typeof nextProps.pagination.options.page !== 'undefined') {
|
||||
this.currPage = nextProps.pagination.options.page;
|
||||
}
|
||||
if (typeof nextProps.pagination.options.sizePerPage !== 'undefined') {
|
||||
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
|
||||
}
|
||||
if (typeof nextProps.pagination.options.totalSize !== 'undefined') {
|
||||
this.dataSize = nextProps.pagination.options.totalSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,13 +123,14 @@ class StateProvider extends React.Component {
|
||||
const { pagination: { options } } = this.props;
|
||||
const pageStartIndex = typeof options.pageStartIndex === 'undefined' ?
|
||||
Const.PAGE_START_INDEX : options.pageStartIndex;
|
||||
this.dataSize = newDataSize;
|
||||
this.currPage = alignPage(
|
||||
newDataSize,
|
||||
this.dataSize,
|
||||
this.currPage,
|
||||
this.currSizePerPage,
|
||||
pageStartIndex
|
||||
);
|
||||
this.dataSize = newDataSize;
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,18 +43,132 @@ describe('Page Functions', () => {
|
||||
});
|
||||
|
||||
describe('alignPage', () => {
|
||||
const pageStartIndex = 1;
|
||||
const sizePerPage = 10;
|
||||
const page = 3;
|
||||
describe('if the page does not fit the pages which calculated from the length of data', () => {
|
||||
it('should return pageStartIndex argument', () => {
|
||||
expect(alignPage(15, page, sizePerPage, pageStartIndex)).toEqual(pageStartIndex);
|
||||
let newDataSize;
|
||||
let prevDataSize;
|
||||
let currPage;
|
||||
let pageStartIndex;
|
||||
let sizePerPage;
|
||||
|
||||
describe('if prevDataSize < newDataSize', () => {
|
||||
beforeEach(() => {
|
||||
newDataSize = 10;
|
||||
prevDataSize = 6;
|
||||
currPage = 2;
|
||||
pageStartIndex = 1;
|
||||
sizePerPage = 5;
|
||||
});
|
||||
it('should return same page', () => {
|
||||
expect(alignPage(
|
||||
newDataSize,
|
||||
prevDataSize,
|
||||
currPage,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
)).toEqual(currPage);
|
||||
});
|
||||
});
|
||||
|
||||
describe('if the length of store.data is large than the end page index', () => {
|
||||
it('should return current page', () => {
|
||||
expect(alignPage(30, page, sizePerPage, pageStartIndex)).toEqual(page);
|
||||
describe('if currPage < newDataSize', () => {
|
||||
beforeEach(() => {
|
||||
newDataSize = 10;
|
||||
prevDataSize = 12;
|
||||
currPage = 0;
|
||||
pageStartIndex = 1;
|
||||
sizePerPage = 5;
|
||||
});
|
||||
|
||||
it('should return correct page', () => {
|
||||
expect(alignPage(
|
||||
newDataSize,
|
||||
prevDataSize,
|
||||
currPage,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
)).toEqual(pageStartIndex);
|
||||
});
|
||||
});
|
||||
|
||||
describe('if partStartIndex is default 1', () => {
|
||||
describe('and currPage is bigger than newest last page', () => {
|
||||
beforeEach(() => {
|
||||
newDataSize = 9;
|
||||
prevDataSize = 12;
|
||||
currPage = 3;
|
||||
pageStartIndex = 1;
|
||||
sizePerPage = 5;
|
||||
});
|
||||
|
||||
it('should return correct page', () => {
|
||||
expect(alignPage(
|
||||
newDataSize,
|
||||
prevDataSize,
|
||||
currPage,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
)).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and currPage is short than newest last page', () => {
|
||||
beforeEach(() => {
|
||||
newDataSize = 11;
|
||||
prevDataSize = 12;
|
||||
currPage = 3;
|
||||
pageStartIndex = 1;
|
||||
sizePerPage = 5;
|
||||
});
|
||||
|
||||
it('should return correct page', () => {
|
||||
expect(alignPage(
|
||||
newDataSize,
|
||||
prevDataSize,
|
||||
currPage,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
)).toEqual(currPage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('if partStartIndex is default 0', () => {
|
||||
describe('and currPage is bigger than newest last page', () => {
|
||||
beforeEach(() => {
|
||||
newDataSize = 8;
|
||||
prevDataSize = 11;
|
||||
currPage = 2;
|
||||
pageStartIndex = 0;
|
||||
sizePerPage = 5;
|
||||
});
|
||||
|
||||
it('should return correct page', () => {
|
||||
expect(alignPage(
|
||||
newDataSize,
|
||||
prevDataSize,
|
||||
currPage,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
)).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and currPage is short than newest last page', () => {
|
||||
beforeEach(() => {
|
||||
newDataSize = 11;
|
||||
prevDataSize = 12;
|
||||
currPage = 2;
|
||||
pageStartIndex = 0;
|
||||
sizePerPage = 5;
|
||||
});
|
||||
|
||||
it('should return correct page', () => {
|
||||
expect(alignPage(
|
||||
newDataSize,
|
||||
prevDataSize,
|
||||
currPage,
|
||||
sizePerPage,
|
||||
pageStartIndex
|
||||
)).toEqual(currPage);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,6 +67,19 @@ const { SearchBar } = Search;
|
||||
|
||||
3. You should render `SearchBar` with `searchProps` as well. The position of `SearchBar` is depends on you.
|
||||
|
||||
### `SearchBar` Props
|
||||
#### className - [string]
|
||||
Custom the class on input element.
|
||||
|
||||
#### placeholder - [string]
|
||||
Custom the placeholder on input element.
|
||||
|
||||
#### style - [object]
|
||||
Custom the style on input element.
|
||||
|
||||
#### delay = [number]
|
||||
milionsecond for debounce user input.
|
||||
|
||||
### Search Options
|
||||
|
||||
#### defaultSearch - [string]
|
||||
@@ -127,6 +140,8 @@ const { SearchBar, ClearSearchButton } = Search;
|
||||
</ToolkitProvider>
|
||||
```
|
||||
|
||||
-----
|
||||
|
||||
## Export CSV
|
||||
There are two steps to enable the export CSV functionality:
|
||||
|
||||
@@ -176,6 +191,13 @@ Default is `true`. `false` will only export current data which display on table.
|
||||
#### onlyExportSelection - [bool]
|
||||
Default is `false`. `true` will only export the data which is selected.
|
||||
|
||||
#### onlyExportFiltered - [bool]
|
||||
Default is `false`. `true` will only export the data which is filtered/searched.
|
||||
|
||||
>> When you configure this prop as true, you must turn off `exportAll`.
|
||||
|
||||
-----
|
||||
|
||||
## Column Toggle
|
||||
|
||||
Let's see how to render the column toggle in your react component:
|
||||
|
||||
@@ -30,6 +30,7 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
|
||||
ignoreHeader: PropTypes.bool,
|
||||
noAutoBOM: PropTypes.bool,
|
||||
exportAll: PropTypes.bool,
|
||||
onlyExportFiltered: PropTypes.bool,
|
||||
onlyExportSelection: PropTypes.bool
|
||||
})
|
||||
])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-toolkit",
|
||||
"version": "1.3.0",
|
||||
"version": "1.4.0",
|
||||
"description": "The toolkit for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -5,12 +5,14 @@ const ExportCSVButton = (props) => {
|
||||
const {
|
||||
onExport,
|
||||
children,
|
||||
className,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={ `react-bs-table-csv-btn btn btn-default ${className}` }
|
||||
onClick={ () => onExport() }
|
||||
{ ...rest }
|
||||
>
|
||||
@@ -26,7 +28,7 @@ ExportCSVButton.propTypes = {
|
||||
style: PropTypes.object
|
||||
};
|
||||
ExportCSVButton.defaultProps = {
|
||||
className: 'react-bs-table-csv-btn btn btn-default',
|
||||
className: '',
|
||||
style: {}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,19 +27,24 @@ export default Base =>
|
||||
data = source;
|
||||
} else if (options.exportAll) {
|
||||
data = this.props.data;
|
||||
} else if (options.onlyExportFiltered) {
|
||||
const payload = {};
|
||||
this.tableExposedAPIEmitter.emit('get.filtered.rows', payload);
|
||||
data = payload.result;
|
||||
} else {
|
||||
const payload = {};
|
||||
this.tableExposedAPIEmitter.emit('get.table.data', payload);
|
||||
data = payload.result;
|
||||
}
|
||||
|
||||
// filter data
|
||||
// filter data by row selection
|
||||
if (options.onlyExportSelection) {
|
||||
const payload = {};
|
||||
this.tableExposedAPIEmitter.emit('get.selected.rows', payload);
|
||||
const selections = payload.result;
|
||||
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
||||
}
|
||||
|
||||
const content = transform(data, meta, this._.get, options);
|
||||
save(content, options);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,21 @@ import PropTypes from 'prop-types';
|
||||
|
||||
const ClearButton = ({
|
||||
onClear,
|
||||
text
|
||||
text,
|
||||
className
|
||||
}) => (
|
||||
<button className="btn btn-default" onClick={ onClear }>{ text }</button>
|
||||
<button className={ `btn btn-default ${className}` } onClick={ onClear }>{ text }</button>
|
||||
);
|
||||
|
||||
ClearButton.propTypes = {
|
||||
onClear: PropTypes.func.isRequired,
|
||||
className: PropTypes.string,
|
||||
text: PropTypes.string
|
||||
};
|
||||
|
||||
ClearButton.defaultProps = {
|
||||
text: 'Clear'
|
||||
text: 'Clear',
|
||||
className: ''
|
||||
};
|
||||
|
||||
export default ClearButton;
|
||||
|
||||
@@ -59,6 +59,10 @@ export default (options = {
|
||||
}
|
||||
}
|
||||
|
||||
getSearched() {
|
||||
return this.state.data;
|
||||
}
|
||||
|
||||
triggerListener(result) {
|
||||
if (this.props.dataChangeListener) {
|
||||
this.props.dataChangeListener.emit('filterChanged', result.length);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table-next",
|
||||
"version": "2.2.0",
|
||||
"version": "3.1.0",
|
||||
"description": "Next generation of react-bootstrap-table",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
@@ -37,6 +37,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"classnames": "2.2.5",
|
||||
"react-transition-group": "2.5.3",
|
||||
"underscore": "1.9.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
3
packages/react-bootstrap-table2/src/body.js
vendored
3
packages/react-bootstrap-table2/src/body.js
vendored
@@ -17,7 +17,6 @@ class Body extends React.Component {
|
||||
super(props);
|
||||
const {
|
||||
keyField,
|
||||
visibleColumnSize,
|
||||
cellEdit,
|
||||
selectRow,
|
||||
expandRow
|
||||
@@ -34,7 +33,7 @@ class Body extends React.Component {
|
||||
const expandRowEnabled = !!expandRow.renderer;
|
||||
|
||||
if (expandRowEnabled) {
|
||||
RowComponent = withRowExpansion(RowAggregator, visibleColumnSize);
|
||||
RowComponent = withRowExpansion(RowAggregator);
|
||||
}
|
||||
|
||||
if (selectRowEnabled) {
|
||||
|
||||
3
packages/react-bootstrap-table2/src/cell.js
vendored
3
packages/react-bootstrap-table2/src/cell.js
vendored
@@ -23,7 +23,10 @@ class Cell extends eventDelegater(Component) {
|
||||
|
||||
if (shouldUpdate) return true;
|
||||
|
||||
// if (nextProps.formatter)
|
||||
|
||||
shouldUpdate =
|
||||
(nextProps.column.formatter ? !_.isEqual(this.props.row, nextProps.row) : false) ||
|
||||
this.props.column.hidden !== nextProps.column.hidden ||
|
||||
this.props.rowIndex !== nextProps.rowIndex ||
|
||||
this.props.columnIndex !== nextProps.columnIndex ||
|
||||
|
||||
@@ -23,6 +23,15 @@ const withContext = Base =>
|
||||
const exposedAPIEmitter = new EventEmitter();
|
||||
exposedAPIEmitter.on('get.table.data', payload => payload.result = this.table.getData());
|
||||
exposedAPIEmitter.on('get.selected.rows', payload => payload.result = this.selectionContext.getSelected());
|
||||
exposedAPIEmitter.on('get.filtered.rows', (payload) => {
|
||||
if (this.searchContext) {
|
||||
payload.result = this.searchContext.getSearched();
|
||||
} else if (this.filterContext) {
|
||||
payload.result = this.filterContext.getFiltered();
|
||||
} else {
|
||||
payload.result = this.table.getData();
|
||||
}
|
||||
});
|
||||
props.registerExposedAPI(exposedAPIEmitter);
|
||||
}
|
||||
|
||||
@@ -294,6 +303,7 @@ const withContext = Base =>
|
||||
return rootProps => (
|
||||
<this.CellEditContext.Provider
|
||||
{ ...baseProps }
|
||||
ref={ n => this.cellEditContext = n }
|
||||
selectRow={ this.props.selectRow }
|
||||
cellEdit={ this.props.cellEdit }
|
||||
data={ rootProps.getData() }
|
||||
|
||||
@@ -10,18 +10,31 @@ class RowExpandProvider extends React.Component {
|
||||
children: PropTypes.node.isRequired,
|
||||
data: PropTypes.array.isRequired,
|
||||
keyField: PropTypes.string.isRequired
|
||||
}
|
||||
};
|
||||
|
||||
state = { expanded: this.props.expandRow.expanded || [] };
|
||||
state = { expanded: this.props.expandRow.expanded || [],
|
||||
isClosing: this.props.expandRow.isClosing || [] };
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.expandRow) {
|
||||
const isClosing = this.state.expanded.reduce((acc, cur) => {
|
||||
if (!nextProps.expandRow.expanded.includes(cur)) {
|
||||
acc.push(cur);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
this.setState(() => ({ expanded: nextProps.expandRow.expanded, isClosing }));
|
||||
} else {
|
||||
this.setState(() => ({
|
||||
expanded: nextProps.expandRow.expanded || this.state.expanded
|
||||
expanded: this.state.expanded
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
onClosed = (closedRow) => {
|
||||
this.setState({ isClosing: this.state.isClosing.filter(value => value !== closedRow) });
|
||||
};
|
||||
|
||||
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
||||
const { data, keyField, expandRow: { onExpand, onlyOneExpanding, nonExpandable } } = this.props;
|
||||
if (nonExpandable && nonExpandable.includes(rowKey)) {
|
||||
@@ -29,11 +42,15 @@ class RowExpandProvider extends React.Component {
|
||||
}
|
||||
|
||||
let currExpanded = [...this.state.expanded];
|
||||
let isClosing = [...this.state.isClosing];
|
||||
|
||||
if (expanded) {
|
||||
if (onlyOneExpanding) currExpanded = [rowKey];
|
||||
else currExpanded.push(rowKey);
|
||||
if (onlyOneExpanding) {
|
||||
isClosing = isClosing.concat(currExpanded);
|
||||
currExpanded = [rowKey];
|
||||
} else currExpanded.push(rowKey);
|
||||
} else {
|
||||
isClosing.push(rowKey);
|
||||
currExpanded = currExpanded.filter(value => value !== rowKey);
|
||||
}
|
||||
|
||||
@@ -41,8 +58,8 @@ class RowExpandProvider extends React.Component {
|
||||
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
|
||||
onExpand(row, expanded, rowIndex, e);
|
||||
}
|
||||
this.setState(() => ({ expanded: currExpanded }));
|
||||
}
|
||||
this.setState(() => ({ expanded: currExpanded, isClosing }));
|
||||
};
|
||||
|
||||
handleAllRowExpand = (e, expandAll) => {
|
||||
const {
|
||||
@@ -68,7 +85,7 @@ class RowExpandProvider extends React.Component {
|
||||
}
|
||||
|
||||
this.setState(() => ({ expanded: currExpanded }));
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { data, keyField } = this.props;
|
||||
@@ -78,6 +95,8 @@ class RowExpandProvider extends React.Component {
|
||||
...this.props.expandRow,
|
||||
nonExpandable: this.props.expandRow.nonExpandable,
|
||||
expanded: this.state.expanded,
|
||||
isClosing: this.state.isClosing,
|
||||
onClosed: this.onClosed,
|
||||
isAnyExpands: dataOperator.isAnyExpands(data, keyField, this.state.expanded),
|
||||
onRowExpand: this.handleRowExpand,
|
||||
onAllRowExpand: this.handleAllRowExpand
|
||||
|
||||
@@ -14,26 +14,27 @@ class SelectionProvider extends React.Component {
|
||||
keyField: PropTypes.string.isRequired
|
||||
}
|
||||
|
||||
state = { selected: this.props.selectRow.selected || [] };
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.selected = props.selectRow.selected || [];
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.selectRow) {
|
||||
this.setState(() => ({
|
||||
selected: nextProps.selectRow.selected || this.state.selected
|
||||
}));
|
||||
this.selected = nextProps.selectRow.selected || this.selected;
|
||||
}
|
||||
}
|
||||
|
||||
// exposed API
|
||||
getSelected() {
|
||||
return this.state.selected;
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
handleRowSelect = (rowKey, checked, rowIndex, e) => {
|
||||
const { data, keyField, selectRow: { mode, onSelect } } = this.props;
|
||||
const { ROW_SELECT_SINGLE } = Const;
|
||||
|
||||
let currSelected = [...this.state.selected];
|
||||
let currSelected = [...this.selected];
|
||||
|
||||
let result = true;
|
||||
if (onSelect) {
|
||||
@@ -41,18 +42,17 @@ class SelectionProvider extends React.Component {
|
||||
result = onSelect(row, checked, rowIndex, e);
|
||||
}
|
||||
|
||||
this.setState(() => {
|
||||
if (result === true || result === undefined) {
|
||||
if (mode === ROW_SELECT_SINGLE) { // when select mode is radio
|
||||
currSelected = [rowKey];
|
||||
} else if (checked) { // when select mode is checkbox
|
||||
currSelected.push(rowKey);
|
||||
} else {
|
||||
currSelected = currSelected.filter(value => value !== rowKey);
|
||||
}
|
||||
if (result === true || result === undefined) {
|
||||
if (mode === ROW_SELECT_SINGLE) { // when select mode is radio
|
||||
currSelected = [rowKey];
|
||||
} else if (checked) { // when select mode is checkbox
|
||||
currSelected.push(rowKey);
|
||||
} else {
|
||||
currSelected = currSelected.filter(value => value !== rowKey);
|
||||
}
|
||||
return { selected: currSelected };
|
||||
});
|
||||
}
|
||||
this.selected = currSelected;
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
handleAllRowsSelect = (e, isUnSelect) => {
|
||||
@@ -64,7 +64,7 @@ class SelectionProvider extends React.Component {
|
||||
nonSelectable
|
||||
}
|
||||
} = this.props;
|
||||
const { selected } = this.state;
|
||||
const { selected } = this;
|
||||
|
||||
let currSelected;
|
||||
|
||||
@@ -81,7 +81,7 @@ class SelectionProvider extends React.Component {
|
||||
dataOperator.getSelectedRows(
|
||||
data,
|
||||
keyField,
|
||||
isUnSelect ? this.state.selected : currSelected
|
||||
isUnSelect ? selected : currSelected
|
||||
),
|
||||
e
|
||||
);
|
||||
@@ -89,7 +89,8 @@ class SelectionProvider extends React.Component {
|
||||
currSelected = result;
|
||||
}
|
||||
}
|
||||
this.setState(() => ({ selected: currSelected }));
|
||||
this.selected = currSelected;
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -99,7 +100,7 @@ class SelectionProvider extends React.Component {
|
||||
} = getSelectionSummary(
|
||||
this.props.data,
|
||||
this.props.keyField,
|
||||
this.state.selected
|
||||
this.selected
|
||||
);
|
||||
|
||||
let checkedStatus;
|
||||
@@ -113,7 +114,7 @@ class SelectionProvider extends React.Component {
|
||||
<SelectionContext.Provider
|
||||
value={ {
|
||||
...this.props.selectRow,
|
||||
selected: this.state.selected,
|
||||
selected: this.selected,
|
||||
onRowSelect: this.handleRowSelect,
|
||||
onAllRowsSelect: this.handleAllRowsSelect,
|
||||
allRowsSelected,
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
|
||||
const ExpandRow = ({ children, ...rest }) => (
|
||||
<tr className="expanding-row">
|
||||
<td { ...rest }>{ children }</td>
|
||||
const ExpandRow = ({ children, expanded, onClosed, ...rest }) => (
|
||||
<tr>
|
||||
<td className="reset-expansion-style" { ...rest }>
|
||||
<CSSTransition
|
||||
appear
|
||||
in={ expanded }
|
||||
timeout={ 400 }
|
||||
classNames="row-expand-slide"
|
||||
onExited={ onClosed }
|
||||
>
|
||||
<div>
|
||||
<div className="row-expansion-style">
|
||||
{ children }
|
||||
</div>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
|
||||
ExpandRow.propTypes = {
|
||||
children: PropTypes.node
|
||||
children: PropTypes.node,
|
||||
expanded: PropTypes.bool,
|
||||
onClosed: PropTypes.func
|
||||
};
|
||||
|
||||
ExpandRow.defaultProps = {
|
||||
children: null
|
||||
children: null,
|
||||
expanded: false,
|
||||
onClosed: null
|
||||
};
|
||||
|
||||
export default ExpandRow;
|
||||
|
||||
@@ -3,13 +3,13 @@ import React from 'react';
|
||||
import ExpandRow from './expand-row';
|
||||
import ExpansionContext from '../contexts/row-expand-context';
|
||||
|
||||
export default (Component, visibleColumnSize) => {
|
||||
export default (Component) => {
|
||||
const renderWithExpansion = (props, expandRow) => {
|
||||
const key = props.value;
|
||||
|
||||
const expanded = expandRow.expanded.includes(key);
|
||||
const isClosing = expandRow.isClosing.includes(key);
|
||||
const expandable = !expandRow.nonExpandable || !expandRow.nonExpandable.includes(key);
|
||||
|
||||
return [
|
||||
<Component
|
||||
{ ...props }
|
||||
@@ -18,9 +18,11 @@ export default (Component, visibleColumnSize) => {
|
||||
expandable={ expandable }
|
||||
expandRow={ { ...expandRow } }
|
||||
/>,
|
||||
expanded ? <ExpandRow
|
||||
expanded || isClosing ? <ExpandRow
|
||||
key={ `${key}-expanding` }
|
||||
colSpan={ visibleColumnSize }
|
||||
colSpan={ props.visibleColumnSize }
|
||||
expanded={ expanded }
|
||||
onClosed={ () => expandRow.onClosed(key) }
|
||||
>
|
||||
{ expandRow.renderer(props.row) }
|
||||
</ExpandRow> : null
|
||||
|
||||
@@ -8,7 +8,8 @@ export default ExtendBase =>
|
||||
return (
|
||||
nextProps.editingRowIdx === nextProps.rowIndex ||
|
||||
(this.props.editingRowIdx === nextProps.rowIndex &&
|
||||
nextProps.editingRowIdx === null)
|
||||
nextProps.editingRowIdx === null) ||
|
||||
this.props.editingRowIdx === nextProps.rowIndex
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ export default ExtendBase =>
|
||||
return true;
|
||||
}
|
||||
for (let i = 0; i < this.props.columns.length; i += 1) {
|
||||
if (this.props.columns[i].hidden !== nextProps.columns[i].hidden) {
|
||||
if (!_.isEqual(this.props.columns[i], nextProps.columns[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +68,6 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
tr.expanding-row {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
td.react-bootstrap-table-editing-cell {
|
||||
.animated {
|
||||
animation-fill-mode: both;
|
||||
@@ -161,4 +157,26 @@
|
||||
animation-name: bounceOut;
|
||||
}
|
||||
}
|
||||
.reset-expansion-style{
|
||||
padding: 0;
|
||||
}
|
||||
.row-expansion-style{
|
||||
padding: 8px;
|
||||
}
|
||||
.row-expand-slide-appear{
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.row-expand-slide-appear-active{
|
||||
max-height: 1000px;
|
||||
transition: max-height 3s linear;
|
||||
}
|
||||
.row-expand-slide-exit{
|
||||
max-height: 1000px;
|
||||
}
|
||||
.row-expand-slide-exit-active{
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height 400ms cubic-bezier(0, 0.95, 0, 0.95)
|
||||
}
|
||||
}
|
||||
@@ -218,6 +218,47 @@ describe('Cell', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.row is change', () => {
|
||||
describe('and column.formatter is enable', () => {
|
||||
const column = { dataField: 'name', text: 'Product Name', formatter: () => 123 };
|
||||
beforeEach(() => {
|
||||
props = {
|
||||
row,
|
||||
columnIndex: 1,
|
||||
rowIndex: 1,
|
||||
tabIndex: 5,
|
||||
column
|
||||
};
|
||||
wrapper = shallow(
|
||||
<Cell { ...props } />);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
nextProps = { ...props, row: { ...row, alert: 'test' } };
|
||||
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||
});
|
||||
});
|
||||
describe('but column.formatter is disable', () => {
|
||||
const column = { dataField: 'name', text: 'Product Name' };
|
||||
beforeEach(() => {
|
||||
props = {
|
||||
row,
|
||||
columnIndex: 1,
|
||||
rowIndex: 1,
|
||||
tabIndex: 5,
|
||||
column
|
||||
};
|
||||
wrapper = shallow(
|
||||
<Cell { ...props } />);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
nextProps = { ...props, row: { ...row, alert: 'test' } };
|
||||
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('if column.isDummyField is true', () => {
|
||||
describe('when content is change', () => {
|
||||
const column = { dataField: '', text: 'Product Name', isDummyField: true };
|
||||
|
||||
@@ -73,15 +73,15 @@ describe('DataContext', () => {
|
||||
expect(SelectionContext.Consumer).toBeDefined();
|
||||
});
|
||||
|
||||
it('should have correct state.data', () => {
|
||||
expect(wrapper.state().selected).toEqual([]);
|
||||
it('should have correct this.selected', () => {
|
||||
expect(wrapper.instance().selected).toEqual([]);
|
||||
});
|
||||
|
||||
it('should pass correct sort props to children element', () => {
|
||||
expect(wrapper.length).toBe(1);
|
||||
expect(mockBase).toHaveBeenCalledWith({
|
||||
...defaultSelectRow,
|
||||
selected: wrapper.state().selected,
|
||||
selected: wrapper.instance().selected,
|
||||
onRowSelect: wrapper.instance().handleRowSelect,
|
||||
onAllRowsSelect: wrapper.instance().handleAllRowsSelect,
|
||||
allRowsNotSelected: true,
|
||||
@@ -104,8 +104,8 @@ describe('DataContext', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should have correct state.selected', () => {
|
||||
expect(wrapper.state().selected).toEqual(newSelectRow.selected);
|
||||
it('should have correct this.selected', () => {
|
||||
expect(wrapper.instance().selected).toEqual(newSelectRow.selected);
|
||||
});
|
||||
|
||||
describe('if nextProps.selectRow is not existing', () => {
|
||||
@@ -120,8 +120,8 @@ describe('DataContext', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should keep origin state.selected', () => {
|
||||
expect(wrapper.state().selected).toEqual(defaultSelected);
|
||||
it('should keep origin this.selected', () => {
|
||||
expect(wrapper.instance().selected).toEqual(defaultSelected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -131,8 +131,8 @@ describe('DataContext', () => {
|
||||
wrapper.instance().componentWillReceiveProps({});
|
||||
});
|
||||
|
||||
it('should not set state.selected', () => {
|
||||
expect(wrapper.state().selected).toEqual([]);
|
||||
it('should not set this.selected', () => {
|
||||
expect(wrapper.instance().selected).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -148,8 +148,8 @@ describe('DataContext', () => {
|
||||
wrapper = shallow(shallowContext(selectRow));
|
||||
});
|
||||
|
||||
it('should have correct state.data', () => {
|
||||
expect(wrapper.state().selected).toEqual(selectRow.selected);
|
||||
it('should have correct this.selected', () => {
|
||||
expect(wrapper.instance().selected).toEqual(selectRow.selected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -164,12 +164,12 @@ describe('DataContext', () => {
|
||||
wrapper = shallow(shallowContext(selectRow));
|
||||
});
|
||||
|
||||
it('should set state.selected correctly', () => {
|
||||
it('should set this.selected correctly', () => {
|
||||
wrapper.instance().handleRowSelect(firstSelectedRow, true, rowIndex);
|
||||
expect(wrapper.state('selected')).toEqual([firstSelectedRow]);
|
||||
expect(wrapper.instance().selected).toEqual([firstSelectedRow]);
|
||||
|
||||
wrapper.instance().handleRowSelect(secondSelectedRow, true, rowIndex);
|
||||
expect(wrapper.state('selected')).toEqual([secondSelectedRow]);
|
||||
expect(wrapper.instance().selected).toEqual([secondSelectedRow]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -178,18 +178,19 @@ describe('DataContext', () => {
|
||||
wrapper = shallow(shallowContext());
|
||||
});
|
||||
|
||||
it('should set state.selected correctly', () => {
|
||||
it('should set this.selected correctly', () => {
|
||||
wrapper.instance().handleRowSelect(firstSelectedRow, true, rowIndex);
|
||||
expect(wrapper.state('selected')).toEqual(expect.arrayContaining([firstSelectedRow]));
|
||||
expect(wrapper.instance().selected).toEqual(expect.arrayContaining([firstSelectedRow]));
|
||||
|
||||
wrapper.instance().handleRowSelect(secondSelectedRow, true, rowIndex);
|
||||
expect(wrapper.state('selected')).toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow]));
|
||||
expect(wrapper.instance().selected)
|
||||
.toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow]));
|
||||
|
||||
wrapper.instance().handleRowSelect(firstSelectedRow, false, rowIndex);
|
||||
expect(wrapper.state('selected')).toEqual(expect.arrayContaining([secondSelectedRow]));
|
||||
expect(wrapper.instance().selected).toEqual(expect.arrayContaining([secondSelectedRow]));
|
||||
|
||||
wrapper.instance().handleRowSelect(secondSelectedRow, false, rowIndex);
|
||||
expect(wrapper.state('selected')).toEqual([]);
|
||||
expect(wrapper.instance().selected).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -220,8 +221,8 @@ describe('DataContext', () => {
|
||||
wrapper.instance().handleAllRowsSelect(e, false);
|
||||
});
|
||||
|
||||
it('should set state.selected correctly', () => {
|
||||
expect(wrapper.state('selected')).toEqual(data.map(d => d[keyField]));
|
||||
it('should set this.selected correctly', () => {
|
||||
expect(wrapper.instance().selected).toEqual(data.map(d => d[keyField]));
|
||||
});
|
||||
|
||||
describe('when selectRow.onSelectAll is defined', () => {
|
||||
@@ -237,7 +238,7 @@ describe('DataContext', () => {
|
||||
it('should call selectRow.onSelectAll correctly', () => {
|
||||
expect(onSelectAll).toHaveBeenCalledWith(
|
||||
true,
|
||||
dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')),
|
||||
dataOperator.getSelectedRows(data, keyField, wrapper.instance().selected),
|
||||
e
|
||||
);
|
||||
});
|
||||
@@ -253,8 +254,8 @@ describe('DataContext', () => {
|
||||
wrapper.instance().handleAllRowsSelect(e, true);
|
||||
});
|
||||
|
||||
it('should set state.selected correctly', () => {
|
||||
expect(wrapper.state('selected')).toEqual([]);
|
||||
it('should set this.selected correctly', () => {
|
||||
expect(wrapper.instance().selected).toEqual([]);
|
||||
});
|
||||
|
||||
describe('when selectRow.onSelectAll is defined', () => {
|
||||
|
||||
Reference in New Issue
Block a user