react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/sort/default-sort-table.js
Allen e1e8c00271
fix #64
* implement default sort

* add story for default sort

* add test for default sort

* patch docs for default sort

* a workaround to avoid render twice by story.add
2017-10-29 16:58:37 +08:00

60 lines
1.1 KiB
JavaScript

/* eslint react/prefer-stateless-function: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table2';
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 = `\
const columns = [{
dataField: 'id',
text: 'Product ID',
sort: true
}, {
dataField: 'name',
text: 'Product Name',
sort: true
}, {
dataField: 'price',
text: 'Product Price',
sort: true
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`;
class DefaultSortTable extends React.PureComponent {
render() {
return (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } defaultSorted={ defaultSorted } />
<Code>{ sourceCode }</Code>
</div>
);
}
}
export default DefaultSortTable;