react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/bootstrap4/sort.js
Chun-MingChen 8b52053af2 Add stories for bootstrap 4
* row-selction, sort and pagination
2018-08-19 01:04:42 +08:00

71 lines
1.3 KiB
JavaScript

/* eslint react/prefer-stateless-function: 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',
sort: true
}];
const defaultSorted = [{
dataField: 'name',
order: 'desc'
}];
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',
sort: true
}];
const defaultSorted = [{
dataField: 'name',
order: 'desc'
}];
<BootstrapTable
bootstrap4
keyField="id"
data={ products }
columns={ columns }
defaultSorted={ defaultSorted }
/>
`;
export default class extends React.PureComponent {
render() {
return (
<div>
<BootstrapTable bootstrap4 keyField="id" data={ products } columns={ columns } defaultSorted={ defaultSorted } />
<Code>{ sourceCode }</Code>
</div>
);
}
}