mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
* beautify code block with google-code-prettify * prettyPrint when componentDidMount * css style for code block * skip rule 'no-unresolved' for eslint * conflict with webpack resolve path * refactor all code block in example folder with component <Code /> * refactor scss folder structure * specify the responsibility for each stylesheet with file name * load local color themes, tomorrow, for google code prettify * re-select demo color and save into variable * unify the color system for storybook
65 lines
1.3 KiB
JavaScript
65 lines
1.3 KiB
JavaScript
/* eslint no-unused-vars: 0 */
|
|
import React from 'react';
|
|
|
|
import { BootstrapTable } from 'react-bootstrap-table2';
|
|
import Code from 'common/codeBlock';
|
|
|
|
const products = [];
|
|
|
|
function addProducts(quantity) {
|
|
const startId = products.length;
|
|
for (let i = 0; i < quantity; i += 1) {
|
|
const id = startId + i;
|
|
products.push({
|
|
id,
|
|
name: `Item name ${id}`,
|
|
price: 2100 + i
|
|
});
|
|
}
|
|
}
|
|
|
|
addProducts(5);
|
|
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name',
|
|
headerClasses: 'demo-row-odd'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price',
|
|
headerClasses: (column, colIndex) => {
|
|
if (colIndex % 2 === 0) return 'demo-row-even';
|
|
return 'demo-row-odd';
|
|
}
|
|
}];
|
|
|
|
const sourceCode = `\
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name',
|
|
headerClasses: 'demo-row-odd'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price',
|
|
headerClasses: (column, colIndex) => {
|
|
if (colIndex % 2 === 0) return 'demo-row-even';
|
|
return 'demo-row-odd';
|
|
}
|
|
}];
|
|
|
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
|
`;
|
|
|
|
export default () => (
|
|
<div>
|
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|