mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
/* 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 columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID',
|
|
sort: true
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name',
|
|
sort: true,
|
|
onSort: (field, order) => {
|
|
console.log(`Sort Field: ${field}, Sort Order: ${order}`);
|
|
}
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
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,
|
|
onSort: (field, order) => {
|
|
console.log(....);
|
|
}
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
|
`;
|
|
|
|
export default () => (
|
|
<div>
|
|
<BootstrapTable keyField="id" data={ products } columns={ columns } defaultSorted={ defaultSorted } />
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|