mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
* 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
95 lines
1.8 KiB
JavaScript
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>
|
|
);
|