react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/columns/nested-data-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

70 lines
1.2 KiB
JavaScript

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: `User Name ${id}`,
phone: 21009831 + i,
address: {
city: 'New York',
postCode: '1111-4512'
}
});
}
}
addProducts(5);
const columns = [{
dataField: 'id',
text: 'User ID'
}, {
dataField: 'name',
text: 'User Name'
}, {
dataField: 'phone',
text: 'Phone'
}, {
dataField: 'address.city',
text: 'City'
}, {
dataField: 'address.postCode',
text: 'PostCode'
}];
const sourceCode = `\
const columns = [{
dataField: 'id',
text: 'User ID'
}, {
dataField: 'name',
text: 'User Name'
}, {
dataField: 'phone',
text: 'Phone'
}, {
dataField: 'address.city',
text: 'City'
}, {
dataField: 'address.postCode',
text: 'PostCode'
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`;
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);