Skip to content

Commit db612ea

Browse files
committed
fix #946
1 parent 4d76d88 commit db612ea

File tree

7 files changed

+108
-19
lines changed

7 files changed

+108
-19
lines changed

docs/row-selection.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [clickToEdit](#clickToEdit)
1717
* [onSelect](#onSelect)
1818
* [onSelectAll](#onSelectAll)
19+
* [selectColumnPosition](#selectColumnPosition)
1920
* [hideSelectColumn](#hideSelectColumn)
2021
* [hideSelectAll](#hideSelectAll)
2122
* [selectionRenderer](#selectionRenderer)
@@ -275,6 +276,16 @@ const selectRow = {
275276
};
276277
```
277278

279+
### <a name='selectColumnPosition'>selectRow.selectColumnPosition - [String]</a>
280+
Default is `left`. You can give this as `right` for rendering selection column in the right side.
281+
282+
```js
283+
const selectRow = {
284+
mode: 'checkbox',
285+
selectColumnPosition: 'right'
286+
};
287+
```
288+
278289
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a>
279290
Default is `false`, if you don't want to have a selection column, give this prop as `true`
280291

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
3+
import BootstrapTable from 'react-bootstrap-table-next';
4+
import Code from 'components/common/code-block';
5+
import { productsGenerator } from 'utils/common';
6+
7+
const products = productsGenerator();
8+
9+
const columns = [{
10+
dataField: 'id',
11+
text: 'Product ID'
12+
}, {
13+
dataField: 'name',
14+
text: 'Product Name'
15+
}, {
16+
dataField: 'price',
17+
text: 'Product Price'
18+
}];
19+
20+
const selectRow = {
21+
mode: 'checkbox',
22+
clickToSelect: true,
23+
selectColumnPosition: 'right'
24+
};
25+
26+
const sourceCode = `\
27+
import BootstrapTable from 'react-bootstrap-table-next';
28+
29+
const columns = [{
30+
dataField: 'id',
31+
text: 'Product ID'
32+
}, {
33+
dataField: 'name',
34+
text: 'Product Name'
35+
}, {
36+
dataField: 'price',
37+
text: 'Product Price'
38+
}];
39+
40+
const selectRow = {
41+
mode: 'checkbox',
42+
clickToSelect: true,
43+
selectColumnPosition: 'right'
44+
};
45+
46+
<BootstrapTable
47+
keyField='id'
48+
data={ products }
49+
columns={ columns }
50+
selectRow={ selectRow }
51+
/>
52+
`;
53+
54+
export default () => (
55+
<div>
56+
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
57+
<Code>{ sourceCode }</Code>
58+
</div>
59+
);

packages/react-bootstrap-table2-example/stories/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
150150
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
151151
import SelectionHooks from 'examples/row-selection/selection-hooks';
152152
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
153+
import SelectionColumnPositionTable from 'examples/row-selection/selection-column-position';
153154

154155
// work on row expand
155156
import BasicRowExpand from 'examples/row-expand';
@@ -394,7 +395,8 @@ storiesOf('Row Selection', module)
394395
.add('Selection Background Color', () => <SelectionBgColorTable />)
395396
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
396397
.add('Selection Hooks', () => <SelectionHooks />)
397-
.add('Hide Selection Column', () => <HideSelectionColumnTable />);
398+
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
399+
.add('Selection Column Position', () => <SelectionColumnPositionTable />);
398400

399401
storiesOf('Row Expand', module)
400402
.addDecorator(bootstrapStyle())

packages/react-bootstrap-table2/src/bootstrap-table.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ BootstrapTable.propTypes = {
168168
hideSelectColumn: PropTypes.bool,
169169
selectionRenderer: PropTypes.func,
170170
selectionHeaderRenderer: PropTypes.func,
171-
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
171+
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
172+
selectColumnPosition: PropTypes.oneOf([
173+
Const.INDICATOR_POSITION_LEFT,
174+
Const.INDICATOR_POSITION_RIGHT
175+
])
172176
}),
173177
expandRow: PropTypes.shape({
174178
renderer: PropTypes.func,

packages/react-bootstrap-table2/src/footer.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const Footer = (props) => {
1111
const SelectionFooterCellComp = () => <th />;
1212
const ExpansionFooterCellComp = () => <th />;
1313

14-
const isRenderExpandColumnInLeft = (
15-
expandColumnPosition = Const.INDICATOR_POSITION_LEFT
16-
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT;
14+
const isRenderFunctionColumnInLeft = (
15+
position = Const.INDICATOR_POSITION_LEFT
16+
) => position === Const.INDICATOR_POSITION_LEFT;
1717

1818
const childrens = columns.map((column, i) => {
1919
if (column.footer === undefined || column.footer === null) {
@@ -33,11 +33,15 @@ const Footer = (props) => {
3333
});
3434

3535
if (selectRow && selectRow.hideSelectColumn !== true) {
36-
childrens.unshift(<SelectionFooterCellComp key="selection" />);
36+
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
37+
childrens.unshift(<SelectionFooterCellComp key="selection" />);
38+
} else {
39+
childrens.push(<SelectionFooterCellComp key="selection" />);
40+
}
3741
}
3842

3943
if (expandRow.showExpandColumn) {
40-
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) {
44+
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
4145
childrens.unshift(<ExpansionFooterCellComp key="expansion" />);
4246
} else {
4347
childrens.push(<ExpansionFooterCellComp key="expansion" />);

packages/react-bootstrap-table2/src/header.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ const Header = (props) => {
3333
SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell);
3434
}
3535

36-
const isRenderExpandColumnInLeft = (
37-
expandColumnPosition = Const.INDICATOR_POSITION_LEFT
38-
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT;
36+
const isRenderFunctionColumnInLeft = (
37+
position = Const.INDICATOR_POSITION_LEFT
38+
) => position === Const.INDICATOR_POSITION_LEFT;
3939

4040
const childrens = [
4141
columns.map((column, i) => {
@@ -58,11 +58,15 @@ const Header = (props) => {
5858
];
5959

6060
if (!selectRow.hideSelectColumn) {
61-
childrens.unshift(<SelectionHeaderCellComp key="selection" />);
61+
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
62+
childrens.unshift(<SelectionHeaderCellComp key="selection" />);
63+
} else {
64+
childrens.push(<SelectionHeaderCellComp key="selection" />);
65+
}
6266
}
6367

6468
if (expandRow.showExpandColumn) {
65-
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) {
69+
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
6670
childrens.unshift(<ExpansionHeaderCellComp key="expansion" />);
6771
} else {
6872
childrens.push(<ExpansionHeaderCellComp key="expansion" />);

packages/react-bootstrap-table2/src/row/aggregate-row.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
4545
return this.shouldUpdateRowContent;
4646
}
4747

48-
isRenderExpandColumnInLeft(
49-
expandColumnPosition = Const.INDICATOR_POSITION_LEFT
48+
isRenderFunctionColumnInLeft(
49+
position = Const.INDICATOR_POSITION_LEFT
5050
) {
51-
return expandColumnPosition === Const.INDICATOR_POSITION_LEFT;
51+
return position === Const.INDICATOR_POSITION_LEFT;
5252
}
5353

5454
render() {
@@ -71,7 +71,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
7171
...rest
7272
} = this.props;
7373
const key = _.get(row, keyField);
74-
const { hideSelectColumn, clickToSelect } = selectRow;
74+
const { hideSelectColumn, selectColumnPosition, clickToSelect } = selectRow;
7575
const { showExpandColumn, expandColumnPosition } = expandRow;
7676

7777
const newAttrs = this.delegate({ ...attrs });
@@ -95,7 +95,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
9595
)];
9696

9797
if (!hideSelectColumn) {
98-
childrens.unshift((
98+
const selectCell = (
9999
<SelectionCell
100100
{ ...selectRow }
101101
key="selection-cell"
@@ -105,7 +105,12 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
105105
disabled={ !selectable }
106106
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
107107
/>
108-
));
108+
);
109+
if (this.isRenderFunctionColumnInLeft(selectColumnPosition)) {
110+
childrens.unshift(selectCell);
111+
} else {
112+
childrens.push(selectCell);
113+
}
109114
}
110115

111116
if (showExpandColumn) {
@@ -120,7 +125,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
120125
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
121126
/>
122127
);
123-
if (this.isRenderExpandColumnInLeft(expandColumnPosition)) {
128+
if (this.isRenderFunctionColumnInLeft(expandColumnPosition)) {
124129
childrens.unshift(expandCell);
125130
} else {
126131
childrens.push(expandCell);

0 commit comments

Comments
 (0)