Merge pull request #973 from react-bootstrap-table/develop

20190610 release
This commit is contained in:
Allen 2019-06-10 20:51:10 +08:00 committed by GitHub
commit 3747c36039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 506 additions and 31 deletions

View File

@ -16,11 +16,13 @@
* [clickToEdit](#clickToEdit) * [clickToEdit](#clickToEdit)
* [onSelect](#onSelect) * [onSelect](#onSelect)
* [onSelectAll](#onSelectAll) * [onSelectAll](#onSelectAll)
* [selectColumnPosition](#selectColumnPosition)
* [hideSelectColumn](#hideSelectColumn) * [hideSelectColumn](#hideSelectColumn)
* [hideSelectAll](#hideSelectAll) * [hideSelectAll](#hideSelectAll)
* [selectionRenderer](#selectionRenderer) * [selectionRenderer](#selectionRenderer)
* [selectionHeaderRenderer](#selectionHeaderRenderer) * [selectionHeaderRenderer](#selectionHeaderRenderer)
* [headerColumnStyle](#headerColumnStyle) * [headerColumnStyle](#headerColumnStyle)
* [selectColumnStyle](#selectColumnStyle)
### <a name="mode">selectRow.mode - [String]</a> ### <a name="mode">selectRow.mode - [String]</a>
@ -224,6 +226,42 @@ const selectRow = {
}; };
``` ```
### <a name='selectColumnStyle'>selectRow.selectColumnStyle - [Object | Function]</a>
A way to custome the selection cell. `selectColumnStyle` not only accept a simple style object but also a callback function for more flexible customization:
### Style Object
```js
const selectRow = {
mode: 'checkbox',
selectColumnStyle: { backgroundColor: 'blue' }
};
```
### Callback Function
If a callback function present, you can get below information to custom the selection cell:
* `checked`: Whether current row is seleccted or not
* `disabled`: Whether current row is disabled or not
* `rowIndex`: Current row index
* `rowKey`: Current row key
```js
const selectRow = {
mode: 'checkbox',
selectColumnStyle: ({
checked,
disabled,
rowIndex,
rowKey
}) => (
// ....
return { backgroundColor: 'blue' };
)
};
```
### <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: This callback function will be called when a row is select/unselect and pass following three arguments:
`row`, `isSelect`, `rowIndex` and `e`. `row`, `isSelect`, `rowIndex` and `e`.
@ -275,6 +313,16 @@ const selectRow = {
}; };
``` ```
### <a name='selectColumnPosition'>selectRow.selectColumnPosition - [String]</a>
Default is `left`. You can give this as `right` for rendering selection column in the right side.
```js
const selectRow = {
mode: 'checkbox',
selectColumnPosition: 'right'
};
```
### <a name='hideSelectColumn'>selectRow.hideSelectColumn - [Bool]</a> ### <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` Default is `false`, if you don't want to have a selection column, give this prop as `true`

View File

@ -89,7 +89,10 @@ const columns = [
In the following, we go though all the predefined editors: In the following, we go though all the predefined editors:
### Dropdown Editor ### Dropdown Editor
Dropdown editor give a select menu to choose a data from a list, the `editor.options` is required property for dropdown editor. Dropdown editor give a select menu to choose a data from a list. When use dropdown editor, either `editor.options` or `editor.getOptions` should be required prop.
#### editor.options
This is most simple case for assign the dropdown options data directly.
```js ```js
import { Type } from 'react-bootstrap-table2-editor'; import { Type } from 'react-bootstrap-table2-editor';
@ -119,6 +122,46 @@ const columns = [
}]; }];
``` ```
#### editor.getOptions
It is much flexible which accept a function and you can assign the dropdown options dynamically.
There are two case for `getOptions`:
* *Synchronous*: Just return the options array in `getOptions` callback function
* *Asynchronous*: Call `setOptions` function argument when you get the options from remote.
```js
// Synchronous
const columns = [
..., {
dataField: 'type',
text: 'Job Type',
editor: {
type: Type.SELECT,
getOptions: () => [.....]
}
}];
// Asynchronous
const columns = [
..., {
dataField: 'type',
text: 'Job Type',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
setTimeout(() => setOptions([...]), 1500);
}
}
}];
```
[here](https://react-bootstrap-table.github.io/react-bootstrap-table2/storybook/index.html?selectedKind=Cell%20Editing&selectedStory=Dropdown%20Editor%20with%20Dynamic%20Options) is an online example.
### Date Editor ### Date Editor
Date editor is use `<input type="date">`, the configuration is very simple: Date editor is use `<input type="date">`, the configuration is very simple:

View File

@ -4,6 +4,15 @@ import cs from 'classnames';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
class DropDownEditor extends Component { class DropDownEditor extends Component {
constructor(props) {
super(props);
let options = props.options;
if (props.getOptions) {
options = props.getOptions(this.setOptions.bind(this)) || [];
}
this.state = { options };
}
componentDidMount() { componentDidMount() {
const { defaultValue, didMount } = this.props; const { defaultValue, didMount } = this.props;
this.select.value = defaultValue; this.select.value = defaultValue;
@ -11,12 +20,16 @@ class DropDownEditor extends Component {
if (didMount) didMount(); if (didMount) didMount();
} }
setOptions(options) {
this.setState({ options });
}
getValue() { getValue() {
return this.select.value; return this.select.value;
} }
render() { render() {
const { defaultValue, didMount, className, options, ...rest } = this.props; const { defaultValue, didMount, getOptions, className, ...rest } = this.props;
const editorClass = cs('form-control editor edit-select', className); const editorClass = cs('form-control editor edit-select', className);
const attr = { const attr = {
@ -31,7 +44,7 @@ class DropDownEditor extends Component {
defaultValue={ defaultValue } defaultValue={ defaultValue }
> >
{ {
options.map(({ label, value }) => ( this.state.options.map(({ label, value }) => (
<option key={ value } value={ value }>{ label }</option> <option key={ value } value={ value }>{ label }</option>
)) ))
} }
@ -52,13 +65,16 @@ DropDownEditor.propTypes = {
label: PropTypes.string, label: PropTypes.string,
value: PropTypes.any value: PropTypes.any
})) }))
]).isRequired, ]),
didMount: PropTypes.func didMount: PropTypes.func,
getOptions: PropTypes.func
}; };
DropDownEditor.defaultProps = { DropDownEditor.defaultProps = {
className: '', className: '',
defaultValue: '', defaultValue: '',
style: {}, style: {},
didMount: undefined options: [],
didMount: undefined,
getOptions: undefined
}; };
export default DropDownEditor; export default DropDownEditor;

View File

@ -0,0 +1,155 @@
/* eslint react/prefer-stateless-function: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
import Code from 'components/common/code-block';
import { jobsGenerator } from 'utils/common';
const jobs = jobsGenerator().map(j => ({
...j,
type2: j.type
}));
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name'
}, {
dataField: 'owner',
text: 'Job Owner'
}, {
dataField: 'type',
text: 'Job Type1',
editor: {
type: Type.SELECT,
getOptions: () => [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
}
}, {
dataField: 'type2',
text: 'Job Type2',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
setTimeout(() => {
setOptions([{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]);
}, 2000);
}
}
}];
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name'
}, {
dataField: 'owner',
text: 'Job Owner'
}, {
dataField: 'type',
text: 'Job Type1',
editor: {
type: Type.SELECT,
getOptions: () => [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
}
}, {
dataField: 'type2',
text: 'Job Type2',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
setTimeout(() => {
setOptions([{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]);
}, 2000);
}
}
}];
<BootstrapTable
keyField="id"
data={ jobs }
columns={ columns }
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
/>
`;
export default () => (
<div>
<h3>Dropdown Editor with Dynamic Options</h3>
<BootstrapTable
keyField="id"
data={ jobs }
columns={ columns }
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
/>
<Code>{ sourceCode }</Code>
</div>
);

View File

@ -0,0 +1,110 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = productsGenerator(2);
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow1 = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: {
backgroundColor: 'grey'
}
};
const sourceCode1 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = ...
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: {
backgroundColor: 'grey'
}
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
selectRow={ selectRow }
/>
`;
const selectRow2 = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: ({
checked,
disabled,
rowIndex,
rowKey
}) => {
if (checked) {
return {
backgroundColor: 'yellow'
};
}
return {
backgroundColor: 'pink'
};
}
};
const sourceCode2 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = ...
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnStyle: ({
checked,
disabled,
rowIndex,
rowKey
}) => {
if (checked) {
return {
backgroundColor: 'yellow'
};
}
return {
backgroundColor: 'pink'
};
}
};
<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>
);

View File

@ -0,0 +1,59 @@
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
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,
selectColumnPosition: 'right'
};
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
selectColumnPosition: 'right'
};
<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>
);

View File

@ -125,6 +125,7 @@ import EditorStyleTable from 'examples/cell-edit/editor-style-table';
import EditorClassTable from 'examples/cell-edit/editor-class-table'; import EditorClassTable from 'examples/cell-edit/editor-class-table';
import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table'; import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table';
import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table'; import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table';
import DropdownEditorWithDynamicOptionsTable from 'examples/cell-edit/dropdown-editor-with-dynamic-options-table';
import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table'; import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table';
import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table'; import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table';
import DateEditorTable from 'examples/cell-edit/date-editor-table'; import DateEditorTable from 'examples/cell-edit/date-editor-table';
@ -149,6 +150,8 @@ import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor'; import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
import SelectionHooks from 'examples/row-selection/selection-hooks'; import SelectionHooks from 'examples/row-selection/selection-hooks';
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column'; import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
import SelectionColumnStyleTable from 'examples/row-selection/select-column-style';
import SelectionColumnPositionTable from 'examples/row-selection/selection-column-position';
// work on row expand // work on row expand
import BasicRowExpand from 'examples/row-expand'; import BasicRowExpand from 'examples/row-expand';
@ -368,6 +371,7 @@ storiesOf('Cell Editing', module)
.add('Custom Editor Style', () => <EditorStyleTable />) .add('Custom Editor Style', () => <EditorStyleTable />)
.add('DoubleClick to Edit with Selection', () => <DBClickEditWithSelection />) .add('DoubleClick to Edit with Selection', () => <DBClickEditWithSelection />)
.add('Dropdown Editor', () => <DropdownEditorTable />) .add('Dropdown Editor', () => <DropdownEditorTable />)
.add('Dropdown Editor with Dynamic Options', () => <DropdownEditorWithDynamicOptionsTable />)
.add('Textarea Editor', () => <TextareaEditorTable />) .add('Textarea Editor', () => <TextareaEditorTable />)
.add('Checkbox Editor', () => <CheckboxEditorTable />) .add('Checkbox Editor', () => <CheckboxEditorTable />)
.add('Date Editor', () => <DateEditorTable />) .add('Date Editor', () => <DateEditorTable />)
@ -392,7 +396,9 @@ storiesOf('Row Selection', module)
.add('Selection Background Color', () => <SelectionBgColorTable />) .add('Selection Background Color', () => <SelectionBgColorTable />)
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />) .add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
.add('Selection Hooks', () => <SelectionHooks />) .add('Selection Hooks', () => <SelectionHooks />)
.add('Hide Selection Column', () => <HideSelectionColumnTable />); .add('Hide Selection Column', () => <HideSelectionColumnTable />)
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
.add('Selection Column Position', () => <SelectionColumnPositionTable />);
storiesOf('Row Expand', module) storiesOf('Row Expand', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())

View File

@ -185,6 +185,9 @@ Default is `false`. Give true to avoid to attach the csv header.
#### noAutoBOM - [bool] #### noAutoBOM - [bool]
Default is `true`. Default is `true`.
#### blobType - [string]
Default is `text/plain;charset=utf-8`. Change to update the blob type of the exported file.
#### exportAll - [bool] #### exportAll - [bool]
Default is `true`. `false` will only export current data which display on table. Default is `true`. `false` will only export current data which display on table.

View File

@ -29,6 +29,7 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
separator: PropTypes.string, separator: PropTypes.string,
ignoreHeader: PropTypes.bool, ignoreHeader: PropTypes.bool,
noAutoBOM: PropTypes.bool, noAutoBOM: PropTypes.bool,
blobType: PropTypes.string,
exportAll: PropTypes.bool, exportAll: PropTypes.bool,
onlyExportFiltered: PropTypes.bool, onlyExportFiltered: PropTypes.bool,
onlyExportSelection: PropTypes.bool onlyExportSelection: PropTypes.bool

View File

@ -54,11 +54,12 @@ export const save = (
content, content,
{ {
noAutoBOM, noAutoBOM,
fileName fileName,
blobType
} }
) => { ) => {
FileSaver.saveAs( FileSaver.saveAs(
new Blob([content], { type: 'text/plain;charset=utf-8' }), new Blob([content], { type: blobType }),
fileName, fileName,
noAutoBOM noAutoBOM
); );

View File

@ -5,6 +5,7 @@ const csvDefaultOptions = {
separator: ',', separator: ',',
ignoreHeader: false, ignoreHeader: false,
noAutoBOM: true, noAutoBOM: true,
blobType: 'text/plain;charset=utf-8',
exportAll: true, exportAll: true,
onlyExportSelection: false onlyExportSelection: false
}; };

View File

@ -168,7 +168,12 @@ BootstrapTable.propTypes = {
hideSelectColumn: PropTypes.bool, hideSelectColumn: PropTypes.bool,
selectionRenderer: PropTypes.func, selectionRenderer: PropTypes.func,
selectionHeaderRenderer: PropTypes.func, selectionHeaderRenderer: PropTypes.func,
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]) headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
selectColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
selectColumnPosition: PropTypes.oneOf([
Const.INDICATOR_POSITION_LEFT,
Const.INDICATOR_POSITION_RIGHT
])
}), }),
expandRow: PropTypes.shape({ expandRow: PropTypes.shape({
renderer: PropTypes.func, renderer: PropTypes.func,

View File

@ -11,9 +11,9 @@ const Footer = (props) => {
const SelectionFooterCellComp = () => <th />; const SelectionFooterCellComp = () => <th />;
const ExpansionFooterCellComp = () => <th />; const ExpansionFooterCellComp = () => <th />;
const isRenderExpandColumnInLeft = ( const isRenderFunctionColumnInLeft = (
expandColumnPosition = Const.INDICATOR_POSITION_LEFT position = Const.INDICATOR_POSITION_LEFT
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT; ) => position === Const.INDICATOR_POSITION_LEFT;
const childrens = columns.map((column, i) => { const childrens = columns.map((column, i) => {
if (column.footer === undefined || column.footer === null) { if (column.footer === undefined || column.footer === null) {
@ -33,11 +33,15 @@ const Footer = (props) => {
}); });
if (selectRow && selectRow.hideSelectColumn !== true) { if (selectRow && selectRow.hideSelectColumn !== true) {
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
childrens.unshift(<SelectionFooterCellComp key="selection" />); childrens.unshift(<SelectionFooterCellComp key="selection" />);
} else {
childrens.push(<SelectionFooterCellComp key="selection" />);
}
} }
if (expandRow.showExpandColumn) { if (expandRow.showExpandColumn) {
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) { if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
childrens.unshift(<ExpansionFooterCellComp key="expansion" />); childrens.unshift(<ExpansionFooterCellComp key="expansion" />);
} else { } else {
childrens.push(<ExpansionFooterCellComp key="expansion" />); childrens.push(<ExpansionFooterCellComp key="expansion" />);

View File

@ -41,7 +41,7 @@ const HeaderCell = (props) => {
const cellAttrs = { const cellAttrs = {
..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs, ..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs,
...headerEvents, ...headerEvents,
tabIndex: index + 1 tabIndex: 0
}; };
let sortSymbol; let sortSymbol;

View File

@ -33,9 +33,9 @@ const Header = (props) => {
SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell); SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell);
} }
const isRenderExpandColumnInLeft = ( const isRenderFunctionColumnInLeft = (
expandColumnPosition = Const.INDICATOR_POSITION_LEFT position = Const.INDICATOR_POSITION_LEFT
) => expandColumnPosition === Const.INDICATOR_POSITION_LEFT; ) => position === Const.INDICATOR_POSITION_LEFT;
const childrens = [ const childrens = [
columns.map((column, i) => { columns.map((column, i) => {
@ -58,11 +58,15 @@ const Header = (props) => {
]; ];
if (!selectRow.hideSelectColumn) { if (!selectRow.hideSelectColumn) {
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
childrens.unshift(<SelectionHeaderCellComp key="selection" />); childrens.unshift(<SelectionHeaderCellComp key="selection" />);
} else {
childrens.push(<SelectionHeaderCellComp key="selection" />);
}
} }
if (expandRow.showExpandColumn) { if (expandRow.showExpandColumn) {
if (isRenderExpandColumnInLeft(expandRow.expandColumnPosition)) { if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
childrens.unshift(<ExpansionHeaderCellComp key="expansion" />); childrens.unshift(<ExpansionHeaderCellComp key="expansion" />);
} else { } else {
childrens.push(<ExpansionHeaderCellComp key="expansion" />); childrens.push(<ExpansionHeaderCellComp key="expansion" />);

View File

@ -5,6 +5,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Const from '../const'; import Const from '../const';
import _ from '../utils';
import { BootstrapContext } from '../contexts/bootstrap'; import { BootstrapContext } from '../contexts/bootstrap';
export default class SelectionCell extends Component { export default class SelectionCell extends Component {
@ -17,7 +18,8 @@ export default class SelectionCell extends Component {
rowIndex: PropTypes.number, rowIndex: PropTypes.number,
tabIndex: PropTypes.number, tabIndex: PropTypes.number,
clickToSelect: PropTypes.bool, clickToSelect: PropTypes.bool,
selectionRenderer: PropTypes.func selectionRenderer: PropTypes.func,
selectColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
} }
constructor() { constructor() {
@ -31,7 +33,8 @@ export default class SelectionCell extends Component {
this.props.selected !== nextProps.selected || this.props.selected !== nextProps.selected ||
this.props.disabled !== nextProps.disabled || this.props.disabled !== nextProps.disabled ||
this.props.rowKey !== nextProps.rowKey || this.props.rowKey !== nextProps.rowKey ||
this.props.tabIndex !== nextProps.tabIndex; this.props.tabIndex !== nextProps.tabIndex ||
this.props.selectColumnStyle !== nextProps.selectColumnStyle;
return shouldUpdate; return shouldUpdate;
} }
@ -57,17 +60,28 @@ export default class SelectionCell extends Component {
render() { render() {
const { const {
rowKey,
mode: inputType, mode: inputType,
selected, selected,
disabled, disabled,
tabIndex, tabIndex,
rowIndex, rowIndex,
selectionRenderer selectionRenderer,
selectColumnStyle
} = this.props; } = this.props;
const attrs = {}; const attrs = {};
if (tabIndex !== -1) attrs.tabIndex = tabIndex; if (tabIndex !== -1) attrs.tabIndex = tabIndex;
attrs.style = _.isFunction(selectColumnStyle) ?
selectColumnStyle({
checked: selected,
disabled,
rowIndex,
rowKey
}) :
selectColumnStyle;
return ( return (
<BootstrapContext.Consumer> <BootstrapContext.Consumer>
{ {

View File

@ -45,10 +45,10 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
return this.shouldUpdateRowContent; return this.shouldUpdateRowContent;
} }
isRenderExpandColumnInLeft( isRenderFunctionColumnInLeft(
expandColumnPosition = Const.INDICATOR_POSITION_LEFT position = Const.INDICATOR_POSITION_LEFT
) { ) {
return expandColumnPosition === Const.INDICATOR_POSITION_LEFT; return position === Const.INDICATOR_POSITION_LEFT;
} }
render() { render() {
@ -71,7 +71,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
...rest ...rest
} = this.props; } = this.props;
const key = _.get(row, keyField); const key = _.get(row, keyField);
const { hideSelectColumn, clickToSelect } = selectRow; const { hideSelectColumn, selectColumnPosition, clickToSelect } = selectRow;
const { showExpandColumn, expandColumnPosition } = expandRow; const { showExpandColumn, expandColumnPosition } = expandRow;
const newAttrs = this.delegate({ ...attrs }); const newAttrs = this.delegate({ ...attrs });
@ -95,7 +95,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
)]; )];
if (!hideSelectColumn) { if (!hideSelectColumn) {
childrens.unshift(( const selectCell = (
<SelectionCell <SelectionCell
{ ...selectRow } { ...selectRow }
key="selection-cell" key="selection-cell"
@ -105,7 +105,12 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
disabled={ !selectable } disabled={ !selectable }
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 } tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
/> />
)); );
if (this.isRenderFunctionColumnInLeft(selectColumnPosition)) {
childrens.unshift(selectCell);
} else {
childrens.push(selectCell);
}
} }
if (showExpandColumn) { if (showExpandColumn) {
@ -120,7 +125,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 } tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
/> />
); );
if (this.isRenderExpandColumnInLeft(expandColumnPosition)) { if (this.isRenderFunctionColumnInLeft(expandColumnPosition)) {
childrens.unshift(expandCell); childrens.unshift(expandCell);
} else { } else {
childrens.push(expandCell); childrens.push(expandCell);