react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/header-columns/column-style-table.js
ChunMing, Chen 67c37e95f9 fix #18
* allow user to customize class for header cell

* add corresponding story

* allow user to customize inline-style for header cell

* add corresponding story

* [test] unit test for headerStyle

* [test] unit test for headerClasses

* update Document
2017-09-02 06:15:34 -05:00

79 lines
1.5 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
});
}
}
addProducts(5);
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name',
headerStyle: {
backgroundColor: '#fea'
}
}, {
dataField: 'price',
text: 'Product Price',
headerStyle: (column, colIndex) => {
if (colIndex % 2 === 0) {
return {
backgroundColor: '#bbe'
};
}
return {
backgroundColor: '#fea'
};
}
}];
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<pre className="prettyprint lang-js"><code className="language-javascript">{`
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name',
headerStyle: {
backgroundColor: '#fea'
}
}, {
dataField: 'price',
text: 'Product Price',
headerStyle: (column, colIndex) => {
if (colIndex % 2 === 0) {
return {
backgroundColor: '#bbe'
};
}
return {
backgroundColor: '#fea'
};
}
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`}
</code></pre>
</div>
);