react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/columns/nested-data-table.js
Allen ae5c677854 Implement stateful layer (#48)
* implement an internal stateful layer for data change(update/insert/delete)

* BootstrapTable -> BootstrapTableful
2017-09-03 02:25:56 -05:00

70 lines
1.2 KiB
JavaScript

import React from 'react';
import { BootstrapTableful } 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'
}];
<BootstrapTableful keyField='id' data={ products } columns={ columns } />
`;
export default () => (
<div>
<BootstrapTableful keyField="id" data={ products } columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);