mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
* add basic stories * add google-prettify * add google-code-prettify-theme * add code example for each story * add column stories * add header column stories
72 lines
1.3 KiB
JavaScript
72 lines
1.3 KiB
JavaScript
/* eslint no-unused-vars: 0 */
|
|
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: `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
|
|
}];
|
|
|
|
export default () => (
|
|
<div>
|
|
<BootstrapTable
|
|
keyField="id"
|
|
data={ products }
|
|
columns={ columns }
|
|
/>
|
|
<pre className="prettyprint lang-js"><code className="language-javascript">{`
|
|
function priceFormatter(column, colIndex) {
|
|
return (
|
|
<h5><strong>$$ { column.text } $$</strong></h5>
|
|
);
|
|
}
|
|
|
|
const columns = [
|
|
// omit...
|
|
{
|
|
dataField: 'price',
|
|
text: 'Product Price',
|
|
headerFormatter: priceFormatter
|
|
}];
|
|
|
|
<BootstrapTable
|
|
keyField="id"
|
|
data={ products }
|
|
columns={ columns }
|
|
/>
|
|
`}
|
|
</code></pre>
|
|
</div>
|
|
);
|