mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
Merge pull request #1195 from react-bootstrap-table/develop
20191207 release
This commit is contained in:
commit
0e7c145f96
@ -28,6 +28,7 @@
|
|||||||
* [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)
|
||||||
@ -199,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.
|
||||||
|
|
||||||
|
|||||||
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>
|
||||||
|
);
|
||||||
@ -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'
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
|
|||||||
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>
|
||||||
|
);
|
||||||
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,6 +18,7 @@ import TabIndexCellTable from 'examples/basic/tabindex-column';
|
|||||||
|
|
||||||
// bootstrap 4
|
// bootstrap 4
|
||||||
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
||||||
|
import Bootstrap4CaptionTable from 'examples/bootstrap4/caption-table';
|
||||||
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
|
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
|
||||||
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
|
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
|
||||||
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
|
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
|
||||||
@ -105,6 +106,8 @@ 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 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';
|
||||||
@ -212,6 +215,7 @@ import CSVColumnType from 'examples/csv/csv-column-type';
|
|||||||
import CustomCSVButton from 'examples/csv/custom-csv-button';
|
import CustomCSVButton from 'examples/csv/custom-csv-button';
|
||||||
import ExportCustomData from 'examples/csv/export-custom-data';
|
import ExportCustomData from 'examples/csv/export-custom-data';
|
||||||
import CustomCSV from 'examples/csv/custom-csv';
|
import CustomCSV from 'examples/csv/custom-csv';
|
||||||
|
import ExportTableFooter from 'examples/csv/export-footer';
|
||||||
|
|
||||||
// Column toggle
|
// Column toggle
|
||||||
import BasicColumnToggle from 'examples/column-toggle';
|
import BasicColumnToggle from 'examples/column-toggle';
|
||||||
@ -268,6 +272,7 @@ storiesOf('Basic Table', module)
|
|||||||
storiesOf('Bootstrap 4', module)
|
storiesOf('Bootstrap 4', module)
|
||||||
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
||||||
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
|
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
|
||||||
|
.add('Table Caption bootstrap 4', () => <Bootstrap4CaptionTable />)
|
||||||
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
|
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
|
||||||
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
|
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
|
||||||
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
|
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
|
||||||
@ -362,6 +367,8 @@ storiesOf('Sort Table', module)
|
|||||||
.add('Default Sort Table', () => <DefaultSortTable />)
|
.add('Default Sort Table', () => <DefaultSortTable />)
|
||||||
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
||||||
.add('Sort Events', () => <SortEvents />)
|
.add('Sort Events', () => <SortEvents />)
|
||||||
|
.add('Sort Management', () => <SortManagement />)
|
||||||
|
.add('One-time Sort Configuation', () => <OneTimeSortConfiguration />)
|
||||||
.add('Custom Sort Value', () => <CustomSortValue />)
|
.add('Custom Sort Value', () => <CustomSortValue />)
|
||||||
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
||||||
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
|
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
|
||||||
@ -482,7 +489,8 @@ storiesOf('Export CSV', module)
|
|||||||
.add('CSV Column Type', () => <CSVColumnType />)
|
.add('CSV Column Type', () => <CSVColumnType />)
|
||||||
.add('Custom CSV Button', () => <CustomCSVButton />)
|
.add('Custom CSV Button', () => <CustomCSVButton />)
|
||||||
.add('Export Custom Data', () => <ExportCustomData />)
|
.add('Export Custom Data', () => <ExportCustomData />)
|
||||||
.add('Custom CSV', () => <CustomCSV />);
|
.add('Custom CSV', () => <CustomCSV />)
|
||||||
|
.add('Export Table Footer', () => <ExportTableFooter />);
|
||||||
|
|
||||||
storiesOf('EmptyTableOverlay', module)
|
storiesOf('EmptyTableOverlay', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
|
|||||||
@ -209,6 +209,9 @@ Custom the csv file separator.
|
|||||||
#### ignoreHeader - [bool]
|
#### ignoreHeader - [bool]
|
||||||
Default is `false`. Give true to avoid to attach the csv header.
|
Default is `false`. Give true to avoid to attach the csv header.
|
||||||
|
|
||||||
|
#### ignoreFooter - [bool]
|
||||||
|
Default is `true`. Give `false` to attach the table footer if enabled.
|
||||||
|
|
||||||
#### noAutoBOM - [bool]
|
#### noAutoBOM - [bool]
|
||||||
Default is `true`.
|
Default is `true`.
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
|
|||||||
fileName: PropTypes.string,
|
fileName: PropTypes.string,
|
||||||
separator: PropTypes.string,
|
separator: PropTypes.string,
|
||||||
ignoreHeader: PropTypes.bool,
|
ignoreHeader: PropTypes.bool,
|
||||||
|
ignoreFooter: PropTypes.bool,
|
||||||
noAutoBOM: PropTypes.bool,
|
noAutoBOM: PropTypes.bool,
|
||||||
blobType: PropTypes.string,
|
blobType: PropTypes.string,
|
||||||
exportAll: PropTypes.bool,
|
exportAll: PropTypes.bool,
|
||||||
|
|||||||
@ -12,17 +12,21 @@ export const getMetaInfo = columns =>
|
|||||||
export: column.csvExport === false ? false : true,
|
export: column.csvExport === false ? false : true,
|
||||||
row: Number(column.row) || 0,
|
row: Number(column.row) || 0,
|
||||||
rowSpan: Number(column.rowSpan) || 1,
|
rowSpan: Number(column.rowSpan) || 1,
|
||||||
colSpan: Number(column.colSpan) || 1
|
colSpan: Number(column.colSpan) || 1,
|
||||||
|
footer: column.footer,
|
||||||
|
footerFormatter: column.footerFormatter
|
||||||
}))
|
}))
|
||||||
.filter(_ => _.export);
|
.filter(_ => _.export);
|
||||||
|
|
||||||
export const transform = (
|
export const transform = (
|
||||||
data,
|
data,
|
||||||
meta,
|
meta,
|
||||||
getValue,
|
columns,
|
||||||
|
_,
|
||||||
{
|
{
|
||||||
separator,
|
separator,
|
||||||
ignoreHeader
|
ignoreHeader,
|
||||||
|
ignoreFooter
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const visibleColumns = meta.filter(m => m.export);
|
const visibleColumns = meta.filter(m => m.export);
|
||||||
@ -37,7 +41,7 @@ export const transform = (
|
|||||||
content += data
|
content += data
|
||||||
.map((row, rowIndex) =>
|
.map((row, rowIndex) =>
|
||||||
visibleColumns.map((m) => {
|
visibleColumns.map((m) => {
|
||||||
let cellContent = getValue(row, m.field);
|
let cellContent = _.get(row, m.field);
|
||||||
if (m.formatter) {
|
if (m.formatter) {
|
||||||
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
||||||
}
|
}
|
||||||
@ -47,6 +51,18 @@ export const transform = (
|
|||||||
return cellContent;
|
return cellContent;
|
||||||
}).join(separator)).join('\n');
|
}).join(separator)).join('\n');
|
||||||
|
|
||||||
|
if (!ignoreFooter) {
|
||||||
|
content += '\n';
|
||||||
|
content += visibleColumns.map((m, i) => {
|
||||||
|
if (typeof m.footer === 'function') {
|
||||||
|
const columnData = _.pluck(data, columns[i].dataField);
|
||||||
|
return `"${m.footer(columnData, columns[i], i)}"`;
|
||||||
|
} else if (m.footerFormatter) {
|
||||||
|
return `"${m.footerFormatter(columns[i], i)}"`;
|
||||||
|
}
|
||||||
|
return `"${m.footer}"`;
|
||||||
|
}).join(separator);
|
||||||
|
}
|
||||||
return content;
|
return content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ const csvDefaultOptions = {
|
|||||||
fileName: 'spreadsheet.csv',
|
fileName: 'spreadsheet.csv',
|
||||||
separator: ',',
|
separator: ',',
|
||||||
ignoreHeader: false,
|
ignoreHeader: false,
|
||||||
|
ignoreFooter: true,
|
||||||
noAutoBOM: true,
|
noAutoBOM: true,
|
||||||
blobType: 'text/plain;charset=utf-8',
|
blobType: 'text/plain;charset=utf-8',
|
||||||
exportAll: true,
|
exportAll: true,
|
||||||
@ -46,7 +47,7 @@ export default Base =>
|
|||||||
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = transform(data, meta, this._.get, options);
|
const content = transform(data, meta, columns, this._, options);
|
||||||
save(content, options);
|
save(content, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -83,7 +83,9 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
|
|
||||||
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
||||||
|
|
||||||
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
const tableCaption = (
|
||||||
|
caption && <Caption bootstrap4={ bootstrap4 }>{ caption }</Caption>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={ tableWrapperClass }>
|
<div className={ tableWrapperClass }>
|
||||||
@ -95,6 +97,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
sortField={ this.props.sortField }
|
sortField={ this.props.sortField }
|
||||||
sortOrder={ this.props.sortOrder }
|
sortOrder={ this.props.sortOrder }
|
||||||
onSort={ this.props.onSort }
|
onSort={ this.props.onSort }
|
||||||
|
globalSortCaret={ this.props.sort && this.props.sort.sortCaret }
|
||||||
onFilter={ this.props.onFilter }
|
onFilter={ this.props.onFilter }
|
||||||
currFilters={ this.props.currFilters }
|
currFilters={ this.props.currFilters }
|
||||||
onExternalFilter={ this.props.onExternalFilter }
|
onExternalFilter={ this.props.onExternalFilter }
|
||||||
@ -230,6 +233,12 @@ BootstrapTable.propTypes = {
|
|||||||
dataField: PropTypes.string.isRequired,
|
dataField: PropTypes.string.isRequired,
|
||||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
||||||
})),
|
})),
|
||||||
|
sort: PropTypes.shape({
|
||||||
|
dataField: PropTypes.string,
|
||||||
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||||
|
sortFunc: PropTypes.func,
|
||||||
|
sortCaret: PropTypes.func
|
||||||
|
}),
|
||||||
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||||
overlay: PropTypes.func,
|
overlay: PropTypes.func,
|
||||||
onTableChange: PropTypes.func,
|
onTableChange: PropTypes.func,
|
||||||
|
|||||||
12
packages/react-bootstrap-table2/src/caption.js
vendored
12
packages/react-bootstrap-table2/src/caption.js
vendored
@ -4,16 +4,22 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
const Caption = (props) => {
|
const Caption = (props) => {
|
||||||
if (!props.children) return null;
|
if (!props.children) return null;
|
||||||
return (
|
|
||||||
<caption>{ props.children }</caption>
|
const caption = props.bootstrap4 ? (
|
||||||
|
<caption style={ { captionSide: 'top' } }>{props.children}</caption>
|
||||||
|
) : (
|
||||||
|
<caption>{props.children}</caption>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return caption;
|
||||||
};
|
};
|
||||||
|
|
||||||
Caption.propTypes = {
|
Caption.propTypes = {
|
||||||
children: PropTypes.oneOfType([
|
children: PropTypes.oneOfType([
|
||||||
PropTypes.node,
|
PropTypes.node,
|
||||||
PropTypes.string
|
PropTypes.string
|
||||||
])
|
]),
|
||||||
|
bootstrap4: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Caption;
|
export default Caption;
|
||||||
|
|||||||
@ -247,6 +247,7 @@ const withContext = Base =>
|
|||||||
ref={ n => this.sortContext = n }
|
ref={ n => this.sortContext = n }
|
||||||
defaultSorted={ this.props.defaultSorted }
|
defaultSorted={ this.props.defaultSorted }
|
||||||
defaultSortDirection={ this.props.defaultSortDirection }
|
defaultSortDirection={ this.props.defaultSortDirection }
|
||||||
|
sort={ this.props.sort }
|
||||||
data={ rootProps.getData(filterProps, searchProps) }
|
data={ rootProps.getData(filterProps, searchProps) }
|
||||||
>
|
>
|
||||||
<this.SortContext.Consumer>
|
<this.SortContext.Consumer>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
@ -19,6 +20,11 @@ export default (
|
|||||||
dataField: PropTypes.string.isRequired,
|
dataField: PropTypes.string.isRequired,
|
||||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
||||||
})),
|
})),
|
||||||
|
sort: PropTypes.shape({
|
||||||
|
dataField: PropTypes.string,
|
||||||
|
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||||
|
sortFunc: PropTypes.func
|
||||||
|
}),
|
||||||
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC])
|
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,19 +32,14 @@ export default (
|
|||||||
super(props);
|
super(props);
|
||||||
let sortOrder;
|
let sortOrder;
|
||||||
let sortColumn;
|
let sortColumn;
|
||||||
const { columns, defaultSorted, defaultSortDirection } = props;
|
const { defaultSorted, defaultSortDirection, sort } = props;
|
||||||
|
|
||||||
if (defaultSorted && defaultSorted.length > 0) {
|
if (defaultSorted && defaultSorted.length > 0) {
|
||||||
const sortField = defaultSorted[0].dataField;
|
|
||||||
sortOrder = defaultSorted[0].order || defaultSortDirection;
|
sortOrder = defaultSorted[0].order || defaultSortDirection;
|
||||||
const sortColumns = columns.filter(col => col.dataField === sortField);
|
sortColumn = this.initSort(defaultSorted[0].dataField, sortOrder);
|
||||||
if (sortColumns.length > 0) {
|
} else if (sort && sort.dataField && sort.order) {
|
||||||
sortColumn = sortColumns[0];
|
sortOrder = sort.order;
|
||||||
|
sortColumn = this.initSort(sort.dataField, sortOrder);
|
||||||
if (sortColumn.onSort) {
|
|
||||||
sortColumn.onSort(sortField, sortOrder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.state = { sortOrder, sortColumn };
|
this.state = { sortOrder, sortColumn };
|
||||||
}
|
}
|
||||||
@ -50,6 +51,30 @@ export default (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||||
|
const { sort, columns } = nextProps;
|
||||||
|
if (sort && sort.dataField && sort.order) {
|
||||||
|
this.setState({
|
||||||
|
sortOrder: sort.order,
|
||||||
|
sortColumn: columns.find(col => col.dataField === sort.dataField)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initSort(sortField, sortOrder) {
|
||||||
|
let sortColumn;
|
||||||
|
const { columns } = this.props;
|
||||||
|
const sortColumns = columns.filter(col => col.dataField === sortField);
|
||||||
|
if (sortColumns.length > 0) {
|
||||||
|
sortColumn = sortColumns[0];
|
||||||
|
|
||||||
|
if (sortColumn.onSort) {
|
||||||
|
sortColumn.onSort(sortField, sortOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sortColumn;
|
||||||
|
}
|
||||||
|
|
||||||
handleSort = (column) => {
|
handleSort = (column) => {
|
||||||
const sortOrder = dataOperator.nextOrder(column, this.state, this.props.defaultSortDirection);
|
const sortOrder = dataOperator.nextOrder(column, this.state, this.props.defaultSortDirection);
|
||||||
|
|
||||||
@ -68,9 +93,11 @@ export default (
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { data } = this.props;
|
let { data } = this.props;
|
||||||
|
const { sort } = this.props;
|
||||||
const { sortOrder, sortColumn } = this.state;
|
const { sortOrder, sortColumn } = this.state;
|
||||||
if (!isRemoteSort() && sortColumn) {
|
if (!isRemoteSort() && sortColumn) {
|
||||||
data = dataOperator.sort(data, sortOrder, sortColumn);
|
const sortFunc = sortColumn.sortFunc ? sortColumn.sortFunc : (sort && sort.sortFunc);
|
||||||
|
data = dataOperator.sort(data, sortOrder, { ...sortColumn, sortFunc });
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -22,7 +22,8 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
onFilter,
|
onFilter,
|
||||||
currFilters,
|
currFilters,
|
||||||
filterPosition,
|
filterPosition,
|
||||||
onExternalFilter
|
onExternalFilter,
|
||||||
|
globalSortCaret
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -42,6 +43,8 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
headerSortingStyle
|
headerSortingStyle
|
||||||
} = column;
|
} = column;
|
||||||
|
|
||||||
|
const sortCaretfunc = sortCaret || globalSortCaret;
|
||||||
|
|
||||||
const delegateEvents = this.delegate(headerEvents);
|
const delegateEvents = this.delegate(headerEvents);
|
||||||
|
|
||||||
const customAttrs = _.isFunction(headerAttrs)
|
const customAttrs = _.isFunction(headerAttrs)
|
||||||
@ -81,7 +84,9 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
cellAttrs.className = cs(cellAttrs.className, 'sortable');
|
cellAttrs.className = cs(cellAttrs.className, 'sortable');
|
||||||
|
|
||||||
if (sorting) {
|
if (sorting) {
|
||||||
sortSymbol = sortCaret ? sortCaret(sortOrder, column) : <SortCaret order={ sortOrder } />;
|
sortSymbol = sortCaretfunc ?
|
||||||
|
sortCaretfunc(sortOrder, column) :
|
||||||
|
<SortCaret order={ sortOrder } />;
|
||||||
|
|
||||||
// append customized classes or style if table was sorting based on the current column.
|
// append customized classes or style if table was sorting based on the current column.
|
||||||
cellClasses = cs(
|
cellClasses = cs(
|
||||||
@ -98,7 +103,7 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
: headerSortingStyle
|
: headerSortingStyle
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
sortSymbol = sortCaret ? sortCaret(undefined, column) : <SortSymbol />;
|
sortSymbol = sortCaretfunc ? sortCaretfunc(undefined, column) : <SortSymbol />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,8 @@ const Header = (props) => {
|
|||||||
expandRow,
|
expandRow,
|
||||||
currFilters,
|
currFilters,
|
||||||
onExternalFilter,
|
onExternalFilter,
|
||||||
filterPosition
|
filterPosition,
|
||||||
|
globalSortCaret
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
let SelectionHeaderCellComp = () => null;
|
let SelectionHeaderCellComp = () => null;
|
||||||
@ -52,6 +53,7 @@ const Header = (props) => {
|
|||||||
onSort={ onSort }
|
onSort={ onSort }
|
||||||
sorting={ currSort }
|
sorting={ currSort }
|
||||||
sortOrder={ sortOrder }
|
sortOrder={ sortOrder }
|
||||||
|
globalSortCaret={ globalSortCaret }
|
||||||
isLastSorting={ isLastSorting }
|
isLastSorting={ isLastSorting }
|
||||||
onFilter={ onFilter }
|
onFilter={ onFilter }
|
||||||
currFilters={ currFilters }
|
currFilters={ currFilters }
|
||||||
@ -95,6 +97,7 @@ Header.propTypes = {
|
|||||||
selectRow: PropTypes.object,
|
selectRow: PropTypes.object,
|
||||||
currFilters: PropTypes.object,
|
currFilters: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func,
|
onExternalFilter: PropTypes.func,
|
||||||
|
globalSortCaret: PropTypes.func,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
expandRow: PropTypes.object,
|
expandRow: PropTypes.object,
|
||||||
filterPosition: PropTypes.oneOf([
|
filterPosition: PropTypes.oneOf([
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user