mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
fix #119
* implement selectRow.hideSelectColumn * add story for selectRow.hideSelectColumn * add tests for selectRow.hideSelectColumn * patch docs for selectRow.hideSelectColumn
This commit is contained in:
parent
ca02af3d6a
commit
ab305a7db2
@ -17,6 +17,7 @@ The following are available properties in `selectRow`:
|
||||
* [clickToEdit](#clickToEdit)
|
||||
* [onSelect](#onSelect)
|
||||
* [onSelectAll](#onSelectAll)
|
||||
* [hideSelectColumn](#hideSelectColumn)
|
||||
|
||||
#### Optional
|
||||
|
||||
@ -148,7 +149,7 @@ const selectRow = {
|
||||
};
|
||||
```
|
||||
|
||||
# <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
||||
## <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
||||
This callback function will be called when a row is select/unselect and pass following three arguments:
|
||||
`row`, `isSelect` and `rowIndex`.
|
||||
|
||||
@ -161,7 +162,7 @@ const selectRow = {
|
||||
};
|
||||
```
|
||||
|
||||
# <a name='onSelectAll'>selectRow.onSelectAll - [Function]</a>
|
||||
## <a name='onSelectAll'>selectRow.onSelectAll - [Function]</a>
|
||||
This callback function will be called when select/unselect all and it only work when you configure [`selectRow.mode`](#mode) as `checkbox`.
|
||||
|
||||
```js
|
||||
@ -172,3 +173,15 @@ const selectRow = {
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
|
||||
Default is `false`, if you don't want to have a selection column, give this prop as `true`
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'radio',
|
||||
hideSelectColumn: true,
|
||||
clickToSelect: true,
|
||||
bgColor: 'red'
|
||||
};
|
||||
```
|
||||
|
||||
59
packages/react-bootstrap-table2-example/examples/row-selection/hide-selection-column.js
vendored
Normal file
59
packages/react-bootstrap-table2-example/examples/row-selection/hide-selection-column.js
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
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 selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
hideSelectColumn: true,
|
||||
bgColor: '#00BFFF'
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
hideSelectColumn: true,
|
||||
bgColor: '#00BFFF'
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
@ -60,6 +60,7 @@ import SelectionClassTable from 'examples/row-selection/selection-class';
|
||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
||||
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
||||
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
||||
|
||||
// css style
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
@ -128,4 +129,5 @@ storiesOf('Row Selection', module)
|
||||
.add('Selection Class', () => <SelectionClassTable />)
|
||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
||||
.add('Selection Hooks', () => <SelectionHooks />);
|
||||
.add('Selection Hooks', () => <SelectionHooks />)
|
||||
.add('Hide Selection Column', () => <HideSelectionColumnTable />);
|
||||
|
||||
@ -135,7 +135,8 @@ BootstrapTable.propTypes = {
|
||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
nonSelectable: PropTypes.array,
|
||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
|
||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
hideSelectColumn: PropTypes.bool
|
||||
}),
|
||||
onRowSelect: PropTypes.func,
|
||||
onAllRowsSelect: PropTypes.func
|
||||
|
||||
@ -7,7 +7,7 @@ import HeaderCell from './header-cell';
|
||||
import SelectionHeaderCell from './row-selection/selection-header-cell';
|
||||
|
||||
const Header = (props) => {
|
||||
const { ROW_SELECT_DISABLED } = Const;
|
||||
const { ROW_SELECT_MULTIPLE } = Const;
|
||||
|
||||
const {
|
||||
columns,
|
||||
@ -21,7 +21,8 @@ const Header = (props) => {
|
||||
<thead>
|
||||
<tr>
|
||||
{
|
||||
selectRow.mode === ROW_SELECT_DISABLED ? null : <SelectionHeaderCell { ...selectRow } />
|
||||
(selectRow.mode === ROW_SELECT_MULTIPLE && !selectRow.hideSelectColumn)
|
||||
? <SelectionHeaderCell { ...selectRow } /> : null
|
||||
}
|
||||
{
|
||||
columns.map((column, i) => {
|
||||
|
||||
8
packages/react-bootstrap-table2/src/row.js
vendored
8
packages/react-bootstrap-table2/src/row.js
vendored
@ -68,7 +68,7 @@ class Row extends Component {
|
||||
} = cellEdit;
|
||||
|
||||
const key = _.get(row, keyField);
|
||||
const { clickToSelect } = selectRow;
|
||||
const { clickToSelect, hideSelectColumn } = selectRow;
|
||||
|
||||
const trAttrs = {};
|
||||
if (clickToSelect) {
|
||||
@ -78,9 +78,8 @@ class Row extends Component {
|
||||
return (
|
||||
<tr style={ style } className={ className } { ...trAttrs }>
|
||||
{
|
||||
selectRow.mode === Const.ROW_SELECT_DISABLED
|
||||
? null
|
||||
: (
|
||||
(selectRow.mode === Const.ROW_SELECT_MULTIPLE && !hideSelectColumn)
|
||||
? (
|
||||
<SelectionCell
|
||||
{ ...selectRow }
|
||||
rowKey={ key }
|
||||
@ -89,6 +88,7 @@ class Row extends Component {
|
||||
disabled={ !selectable }
|
||||
/>
|
||||
)
|
||||
: null
|
||||
}
|
||||
{
|
||||
columns.map((column, index) => {
|
||||
|
||||
@ -53,12 +53,36 @@ describe('Header', () => {
|
||||
|
||||
describe('when the selectRow.mode is radio(single selection)', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<Header { ...mockHeaderResolvedProps } columns={ columns } />);
|
||||
const selectRow = { mode: 'radio' };
|
||||
wrapper = shallow(
|
||||
<Header
|
||||
{ ...mockHeaderResolvedProps }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
it('should not render <SelectionHeaderCell />', () => {
|
||||
expect(wrapper.find(SelectionHeaderCell).length).toBe(0);
|
||||
});
|
||||
|
||||
describe('when selectRow.hideSelectColumn is true', () => {
|
||||
beforeEach(() => {
|
||||
const selectRow = { mode: 'radio', hideSelectColumn: true };
|
||||
wrapper = shallow(
|
||||
<Header
|
||||
{ ...mockHeaderResolvedProps }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
it('should rendering header with selection column', () => {
|
||||
expect(wrapper.find(SelectionHeaderCell).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the selectRow.mode is checkbox(multiple selection)', () => {
|
||||
@ -76,5 +100,22 @@ describe('Header', () => {
|
||||
it('should render <SelectionHeaderCell />', () => {
|
||||
expect(wrapper.find(SelectionHeaderCell).length).toBe(1);
|
||||
});
|
||||
|
||||
describe('when selectRow.hideSelectColumn is true', () => {
|
||||
beforeEach(() => {
|
||||
const selectRow = { mode: 'checkbox', hideSelectColumn: true };
|
||||
wrapper = shallow(
|
||||
<Header
|
||||
{ ...mockHeaderResolvedProps }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
it('should rendering header with selection column', () => {
|
||||
expect(wrapper.find(SelectionHeaderCell).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -545,6 +545,27 @@ describe('Row', () => {
|
||||
expect(wrapper.find('tr').prop('onClick')).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('if selectRow.hideSelectColumn is true', () => {
|
||||
beforeEach(() => {
|
||||
selectRow.hideSelectColumn = true;
|
||||
wrapper = shallow(
|
||||
<Row
|
||||
{ ...mockBodyResolvedProps }
|
||||
rowIndex={ rowIndex }
|
||||
columns={ defaultColumns }
|
||||
row={ row }
|
||||
selectRow={ selectRow }
|
||||
selected
|
||||
selectable
|
||||
/>);
|
||||
});
|
||||
|
||||
it('should render Row component without selection column', () => {
|
||||
expect(wrapper.length).toBe(1);
|
||||
expect(wrapper.find(SelectionCell).length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleRowClick', () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user