mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
100 lines
2.9 KiB
JavaScript
100 lines
2.9 KiB
JavaScript
/* eslint react/prefer-stateless-function: 0 */
|
|
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';
|
|
import { productsGenerator } from 'utils/common';
|
|
|
|
const products = productsGenerator(87);
|
|
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
const sourceCode = `\
|
|
import BootstrapTable from 'react-bootstrap-table-next';
|
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
|
// ...
|
|
|
|
const customTotal = (from, to, size) => (
|
|
<span className="react-bootstrap-table-pagination-total">
|
|
Showing { from } to { to } of { size } Results
|
|
</span>
|
|
);
|
|
|
|
const options = {
|
|
paginationSize: 4,
|
|
pageStartIndex: 0,
|
|
// alwaysShowAllBtns: true, // Always show next and previous button
|
|
// withFirstAndLast: false, // Hide the going to First and Last page button
|
|
// hideSizePerPage: true, // Hide the sizePerPage dropdown always
|
|
// hidePageListOnlyOnePage: true, // Hide the pagination list when only one page
|
|
firstPageText: 'First',
|
|
prePageText: 'Back',
|
|
nextPageText: 'Next',
|
|
lastPageText: 'Last',
|
|
nextPageTitle: 'First page',
|
|
prePageTitle: 'Pre page',
|
|
firstPageTitle: 'Next page',
|
|
lastPageTitle: 'Last page',
|
|
showTotal: true,
|
|
paginationTotalRenderer: customTotal,
|
|
sizePerPageList: [{
|
|
text: '5', value: 5
|
|
}, {
|
|
text: '10', value: 10
|
|
}, {
|
|
text: 'All', value: products.length
|
|
}] // A numeric array is also available. the purpose of above example is custom the text
|
|
};
|
|
|
|
<BootstrapTable keyField='id' data={ products } columns={ columns } pagination={ paginationFactory(options) } />
|
|
`;
|
|
|
|
const customTotal = (from, to, size) => (
|
|
<span className="react-bootstrap-table-pagination-total">
|
|
Showing { from } to { to } of { size } Results
|
|
</span>
|
|
);
|
|
|
|
const options = {
|
|
paginationSize: 4,
|
|
pageStartIndex: 0,
|
|
// alwaysShowAllBtns: true, // Always show next and previous button
|
|
// withFirstAndLast: false, // Hide the going to First and Last page button
|
|
// hideSizePerPage: true, // Hide the sizePerPage dropdown always
|
|
// hidePageListOnlyOnePage: true, // Hide the pagination list when only one page
|
|
firstPageText: 'First',
|
|
prePageText: 'Back',
|
|
nextPageText: 'Next',
|
|
lastPageText: 'Last',
|
|
nextPageTitle: 'First page',
|
|
prePageTitle: 'Pre page',
|
|
firstPageTitle: 'Next page',
|
|
lastPageTitle: 'Last page',
|
|
showTotal: true,
|
|
paginationTotalRenderer: customTotal,
|
|
sizePerPageList: [{
|
|
text: '5', value: 5
|
|
}, {
|
|
text: '10', value: 10
|
|
}, {
|
|
text: 'All', value: products.length
|
|
}] // A numeric array is also available. the purpose of above example is custom the text
|
|
};
|
|
|
|
export default () => (
|
|
<div>
|
|
<BootstrapTable keyField="id" data={ products } columns={ columns } pagination={ paginationFactory(options) } />
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|