react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/row-selection/selection-style.js
Allen 10f06dca10 fix #104
* implement row seleciton style and class

* add testing for row selection style and class

* refine select row test

* add stories for row selection style and class

* add docs for row selection style and class

* patch for wrong docs
2017-10-20 00:44:25 -05:00

95 lines
1.8 KiB
JavaScript

/* eslint no-unused-vars: 0 */
import React from 'react';
import BootstrapTable 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'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow1 = {
mode: 'checkbox',
style: { backgroundColor: '#c8e6c9' }
};
const selectRow2 = {
mode: 'checkbox',
style: (row, rowIndex) => {
const backgroundColor = rowIndex > 1 ? '#00BFFF' : '#00FFFF';
return { backgroundColor };
}
};
const sourceCode1 = `\
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow = {
mode: 'checkbox',
style: { backgroundColor: '#c8e6c9' }
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
selectRow={ selectRow }
/>
`;
const sourceCode2 = `\
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow = {
mode: 'checkbox',
style: (row, rowIndex) => {
const backgroundColor = rowIndex > 1 ? '#00BFFF' : '#00FFFF';
return { backgroundColor };
}
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
selectRow={ selectRow }
/>
`;
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow1 } />
<Code>{ sourceCode1 }</Code>
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow2 } />
<Code>{ sourceCode2 }</Code>
</div>
);