Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const columns = [{
}, {
dataField: 'quality',
text: 'Product Quality',
editorRenderer: (editorProps, value, row, rowIndex, columnIndex) => (
editorRenderer: (editorProps, value, row, column, rowIndex, columnIndex) => (
<QualityRanger { ...editorProps } value={ value } />
)
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';

import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
import { productsGenerator, withOnSale } from 'utils/common';

const products = productsGenerator();
const products = withOnSale(productsGenerator());

function priceFormatter(cell, row) {
if (row.onSale) {
Expand Down
7 changes: 7 additions & 0 deletions packages/react-bootstrap-table2-example/src/utils/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint no-mixed-operators: 0 */
/* eslint no-param-reassign: 0 */

/**
* products generator for stories
Expand All @@ -22,6 +23,12 @@ export const productsGenerator = (quantity = 5, callback) => {
);
};

export const withOnSale = rows => rows.map((row) => {
if (row.id > 2) row.onSale = false;
else row.onSale = true;
return row;
});

export const productsQualityGenerator = (quantity = 5) =>
Array.from({ length: quantity }, (value, index) => ({
id: index,
Expand Down
43 changes: 21 additions & 22 deletions packages/react-bootstrap-table2/src/contexts/selection-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ class SelectionProvider extends React.Component {

let currSelected = [...this.state.selected];

let result = true;
if (onSelect) {
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
result = onSelect(row, checked, rowIndex, e);
}

this.setState(() => {
let result = true;
if (onSelect) {
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
result = onSelect(row, checked, rowIndex, e);
}
if (result === true || result === undefined) {
if (mode === ROW_SELECT_SINGLE) { // when select mode is radio
currSelected = [rowKey];
Expand Down Expand Up @@ -81,24 +82,22 @@ class SelectionProvider extends React.Component {
currSelected = selected.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
}

this.setState(() => {
let result;
if (onSelectAll) {
result = onSelectAll(
!isUnSelect,
dataOperator.getSelectedRows(
data,
keyField,
isUnSelect ? this.state.selected : currSelected
),
e
);
if (Array.isArray(result)) {
currSelected = result;
}
let result;
if (onSelectAll) {
result = onSelectAll(
!isUnSelect,
dataOperator.getSelectedRows(
data,
keyField,
isUnSelect ? this.state.selected : currSelected
),
e
);
if (Array.isArray(result)) {
currSelected = result;
}
return { selected: currSelected };
});
}
this.setState(() => ({ selected: currSelected }));
}

render() {
Expand Down
7 changes: 2 additions & 5 deletions packages/react-bootstrap-table2/src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const Header = (props) => {
sortOrder,
selectRow,
onExternalFilter,
expandRow,
bootstrap4
expandRow
} = props;

let SelectionHeaderCellComp = () => null;
Expand Down Expand Up @@ -50,7 +49,6 @@ const Header = (props) => {
return (
<HeaderCell
index={ i }
bootstrap4={ bootstrap4 }
key={ column.dataField }
column={ column }
onSort={ onSort }
Expand Down Expand Up @@ -78,8 +76,7 @@ Header.propTypes = {
selectRow: PropTypes.object,
onExternalFilter: PropTypes.func,
className: PropTypes.string,
expandRow: PropTypes.object,
bootstrap4: PropTypes.bool
expandRow: PropTypes.object
};

export default Header;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class ExpandCell extends Component {

handleClick(e) {
const { rowKey, expanded, onRowExpand, rowIndex } = this.props;

e.stopPropagation();
onRowExpand(rowKey, !expanded, rowIndex, e);
}

Expand Down