This commit is contained in:
Allen
2018-04-15 17:29:17 +08:00
committed by GitHub
parent b15d7a3412
commit e4b6993692
7 changed files with 35 additions and 31 deletions

View File

@@ -158,12 +158,12 @@ const selectRow = {
### <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`.
`row`, `isSelect`, `rowIndex` and `e`.
```js
const selectRow = {
mode: 'checkbox',
onSelect: (row, isSelect, rowIndex) => {
onSelect: (row, isSelect, rowIndex, e) => {
// ...
}
};
@@ -175,7 +175,7 @@ This callback function will be called when select/unselect all and it only work
```js
const selectRow = {
mode: 'checkbox',
onSelectAll: (isSelect, results) => {
onSelectAll: (isSelect, results, e) => {
// ...
}
};

View File

@@ -22,14 +22,16 @@ const columns = [{
const selectRow = {
mode: 'checkbox',
clickToSelect: true,
onSelect: (row, isSelect, rowIndex) => {
onSelect: (row, isSelect, rowIndex, e) => {
console.log(row.id);
console.log(isSelect);
console.log(rowIndex);
console.log(e);
},
onSelectAll: (isSelect, rows) => {
onSelectAll: (isSelect, rows, e) => {
console.log(isSelect);
console.log(rows);
console.log(e);
}
};
@@ -49,7 +51,18 @@ const columns = [{
const selectRow = {
mode: 'checkbox',
clickToSelect: true
clickToSelect: true,
onSelect: (row, isSelect, rowIndex, e) => {
console.log(row.id);
console.log(isSelect);
console.log(rowIndex);
console.log(e);
},
onSelectAll: (isSelect, rows, e) => {
console.log(isSelect);
console.log(rows);
console.log(e);
}
};
<BootstrapTable

View File

@@ -47,7 +47,7 @@ export default ExtendBase =>
}
if (selectable) {
const key = _.get(row, keyField);
onRowSelect(key, !selected, rowIndex);
onRowSelect(key, !selected, rowIndex, e);
}
};

View File

@@ -28,7 +28,7 @@ export default class SelectionCell extends Component {
return nextProps.selected !== selected;
}
handleClick() {
handleClick(e) {
const {
mode: inputType,
rowKey,
@@ -46,7 +46,7 @@ export default class SelectionCell extends Component {
? true
: !selected;
onRowSelect(rowKey, checked, rowIndex);
onRowSelect(rowKey, checked, rowIndex, e);
}
render() {

View File

@@ -44,10 +44,10 @@ export default class SelectionHeaderCell extends Component {
return nextProps.checkedStatus !== checkedStatus;
}
handleCheckBoxClick() {
handleCheckBoxClick(e) {
const { onAllRowsSelect } = this.props;
onAllRowsSelect();
onAllRowsSelect(e);
}
render() {

View File

@@ -41,7 +41,7 @@ export default Base =>
* @param {String} rowKey - row key of what was selected.
* @param {Boolean} checked - next checked status of input button.
*/
handleRowSelect(rowKey, checked, rowIndex) {
handleRowSelect(rowKey, checked, rowIndex, e) {
const { selectRow: { mode, onSelect }, store } = this.props;
const { ROW_SELECT_SINGLE } = Const;
@@ -59,7 +59,7 @@ export default Base =>
if (onSelect) {
const row = getRowByRowId(store)(rowKey);
onSelect(row, checked, rowIndex);
onSelect(row, checked, rowIndex, e);
}
this.setState(() => ({
@@ -68,18 +68,16 @@ export default Base =>
}
/**
* handle all rows selection on header cell by store.selected or given specific result.
* @param {Boolean} option - customized result for all rows selection
* handle all rows selection on header cell by store.selected
*/
handleAllRowsSelect(option) {
handleAllRowsSelect(e) {
const { store, selectRow: {
onSelectAll,
nonSelectable
} } = this.props;
const selected = isAnySelectedRow(store)(nonSelectable);
// set next status of all row selected by store.selected or customizing by user.
const result = option || !selected;
const result = !selected;
const currSelected = result ?
selectableKeys(store)(nonSelectable) :
@@ -89,7 +87,7 @@ export default Base =>
store.selected = currSelected;
if (onSelectAll) {
onSelectAll(result, getSelectedRows(store));
onSelectAll(result, getSelectedRows(store), e);
}
this.setState(() => ({

View File

@@ -162,14 +162,6 @@ describe('RowSelectionWrapper', () => {
wrapper.instance().handleAllRowsSelect();
expect(wrapper.state('selectedRowKeys')).toEqual([]);
});
it('call handleAllRowsSelect function with a bool args should setting correct state.selectedRowKeys', () => {
wrapper.instance().handleAllRowsSelect(true);
expect(wrapper.state('selectedRowKeys')).toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow]));
wrapper.instance().handleAllRowsSelect(false);
expect(wrapper.state('selectedRowKeys')).toEqual([]);
});
});
describe('when selectRow.onSelect is defined', () => {
@@ -219,13 +211,14 @@ describe('RowSelectionWrapper', () => {
});
it('selectRow.onSelect callback should be called correctly when calling handleRowSelect function', () => {
wrapper.instance().handleAllRowsSelect();
const e = {};
wrapper.instance().handleAllRowsSelect(e);
expect(onSelectAllCallBack.callCount).toEqual(1);
expect(onSelectAllCallBack.calledWith(true, data)).toBeTruthy();
expect(onSelectAllCallBack.calledWith(true, data, e)).toBeTruthy();
wrapper.instance().handleAllRowsSelect();
wrapper.instance().handleAllRowsSelect(e);
expect(onSelectAllCallBack.callCount).toEqual(2);
expect(onSelectAllCallBack.calledWith(false, [])).toBeTruthy();
expect(onSelectAllCallBack.calledWith(false, [], e)).toBeTruthy();
});
});
});