react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/columns/nested-data-table.js
Allen 60d4e7e5d2 fix #34
* add basic stories

* add google-prettify

* add google-code-prettify-theme

* add code example for each story

* add column stories

* add header column stories
2017-09-02 01:54:09 -05:00

67 lines
1.2 KiB
JavaScript

import React from 'react';
import { BootstrapTable } from 'react-bootstrap-table2';
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'
}];
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<pre className="prettyprint lang-js"><code className="language-javascript">{`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 } />
`}
</code></pre>
</div>
);