mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
* redefine cell callback function * it takes 4 argus `content`, `row`, `rowIndex` and `columnIndex` in * sequence. * [test] fix unit test for new callback * correct the version of story for new cell callback * [DOC] re-define structure of Contents of Table * [DOC] update document for attrs * re-write description for each column props * [DOC] update document for headerCell * re-write and add extra description for each header column props
70 lines
1.3 KiB
JavaScript
70 lines
1.3 KiB
JavaScript
/* eslint no-unused-vars: 0 */
|
|
import React from 'react';
|
|
|
|
import { BootstrapTableful } from 'react-bootstrap-table2';
|
|
import Code from 'components/common/code-block';
|
|
import { productsGenerator } from 'utils/common';
|
|
|
|
const products = productsGenerator();
|
|
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID',
|
|
style: {
|
|
fontWeight: 'bold',
|
|
fontSize: '18px'
|
|
}
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name',
|
|
style: (cell, row, rowIndex, colIndex) => {
|
|
if (rowIndex % 2 === 0) {
|
|
return {
|
|
backgroundColor: '#81c784'
|
|
};
|
|
}
|
|
return {
|
|
backgroundColor: '#c8e6c9'
|
|
};
|
|
}
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
const sourceCode = `\
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID',
|
|
style: {
|
|
fontWeight: 'bold',
|
|
fontSize: '18px'
|
|
}
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name',
|
|
style: (cell, row, rowIndex, colIndex) => {
|
|
if (rowIndex % 2 === 0) {
|
|
return {
|
|
backgroundColor: '#81c784'
|
|
};
|
|
}
|
|
return {
|
|
backgroundColor: '#c8e6c9'
|
|
};
|
|
}
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
<BootstrapTableful keyField='id' data={ products } columns={ columns } />
|
|
`;
|
|
|
|
export default () => (
|
|
<div>
|
|
<BootstrapTableful keyField="id" data={ products } columns={ columns } />
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|