react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/header-columns/column-class-table.js
ChunMing, Chen 82b827561d Enhancement/code prettify (#46)
* 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
2017-09-03 00:31:58 -05:00

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>
);