react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/header-columns/column-format-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

74 lines
1.3 KiB
JavaScript

/* eslint no-unused-vars: 0 */
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: `Item name ${id}`,
price: 2100 + i,
onSale: Math.random() >= 0.5
});
}
}
addProducts(5);
function priceFormatter(column, colIndex) {
return (
<h5><strong>$$ { column.text } $$</strong></h5>
);
}
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price',
headerFormatter: priceFormatter
}];
const sourceCode = `\
function priceFormatter(column, colIndex) {
return (
<h5><strong>$$ { column.text } $$</strong></h5>
);
}
const columns = [
// omit...
{
dataField: 'price',
text: 'Product Price',
headerFormatter: priceFormatter
}];
<BootstrapTableful
keyField="id"
data={ products }
columns={ columns }
/>
`;
export default () => (
<div>
<BootstrapTableful
keyField="id"
data={ products }
columns={ columns }
/>
<Code>{ sourceCode }</Code>
</div>
);