mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
* implement selectRow.clickToSelect and selectRow.clickToEdit * add selectRow.clickToSelect and selectRow.clickToEdit stories * add clickToSelect to row selection examples for easier to select row * refine selectRow.nonSelectable * patch tests for selectRow.clickToSelect and selectRow.clickToEdit * patch docs for selectRow.clickToSelect and selectRow.clickToEdit
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',
|
|
clickToSelect: true,
|
|
classes: 'selection-row'
|
|
};
|
|
|
|
const selectRow2 = {
|
|
mode: 'checkbox',
|
|
clickToSelect: true,
|
|
classes: (row, rowIndex) =>
|
|
(rowIndex > 1 ? 'row-index-bigger-than-2101' : 'row-index-small-than-2101')
|
|
};
|
|
|
|
const sourceCode1 = `\
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
const selectRow = {
|
|
mode: 'checkbox',
|
|
clickToSelect: true,
|
|
classes: 'selection-row'
|
|
};
|
|
|
|
<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',
|
|
clickToSelect: true,
|
|
classes: (row, rowIndex) =>
|
|
(rowIndex > 1 ? 'row-index-bigger-than-2101' : 'row-index-small-than-2101')
|
|
};
|
|
|
|
<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>
|
|
);
|