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
@@ -0,0 +1,188 @@
/* eslint no-param-reassign: 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();

const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';

class DummyColumnWithRowExpand extends React.Component {
constructor(props) {
super(props);

this.state = {
hoverIdx: null
};
}

expandRow = {
renderer: () => (
<div style={ { width: '100%', height: '20px' } }>Content</div>
),
showExpandColumn: true,
expandByColumnOnly: true
};

actionFormater = (cell, row, rowIndex, { hoverIdx }) => {
if ((hoverIdx !== null || hoverIdx !== undefined) && hoverIdx === rowIndex) {
return (
<div
style={ { width: '20px', height: '20px', backgroundColor: 'orange' } }
/>
);
}
return (
<div
style={ { width: '20px', height: '20px' } }
/>
);
}

rowEvents = {
onMouseEnter: (e, row, rowIndex) => {
this.setState({ hoverIdx: rowIndex });
},
onMouseLeave: () => {
this.setState({ hoverIdx: null });
}
}

rowStyle = (row, rowIndex) => {
row.index = rowIndex;
const style = {};
if (rowIndex % 2 === 0) {
style.backgroundColor = 'transparent';
} else {
style.backgroundColor = 'rgba(54, 163, 173, .10)';
}
style.borderTop = 'none';

return style;
}

render() {
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}, {
text: '',
isDummyField: true,
formatter: this.actionFormater,
formatExtraData: { hoverIdx: this.state.hoverIdx },
headerStyle: { width: '50px' },
style: { height: '30px' }
}];
return (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
noDataIndication="There is no data"
classes="table"
rowStyle={ this.rowStyle }
rowEvents={ this.rowEvents }
expandRow={ this.expandRow }
/>
</div>
);
}
}
`;

export default class DummyColumnWithRowExpand extends React.Component {
constructor(props) {
super(props);

this.state = {
hoverIdx: null
};
}

expandRow = {
renderer: () => (
<div style={ { width: '100%', height: '20px' } }>Content</div>
),
showExpandColumn: true,
expandByColumnOnly: true
};

actionFormater = (cell, row, rowIndex, { hoverIdx }) => {
if ((hoverIdx !== null || hoverIdx !== undefined) && hoverIdx === rowIndex) {
return (
<div
style={ { width: '20px', height: '20px', backgroundColor: 'orange' } }
/>
);
}
return (
<div
style={ { width: '20px', height: '20px' } }
/>
);
}

rowEvents = {
onMouseEnter: (e, row, rowIndex) => {
this.setState({ hoverIdx: rowIndex });
},
onMouseLeave: () => {
this.setState({ hoverIdx: null });
}
}

rowStyle = (row, rowIndex) => {
row.index = rowIndex;
const style = {};
if (rowIndex % 2 === 0) {
style.backgroundColor = 'transparent';
} else {
style.backgroundColor = 'rgba(54, 163, 173, .10)';
}
style.borderTop = 'none';

return style;
}

render() {
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}, {
isDummyField: true,
text: '',
formatter: this.actionFormater,
formatExtraData: { hoverIdx: this.state.hoverIdx },
headerStyle: { width: '50px' },
style: { height: '30px' }
}];
return (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
rowStyle={ this.rowStyle }
rowEvents={ this.rowEvents }
expandRow={ this.expandRow }
/>
<Code>{ sourceCode }</Code>
</div>
);
}
}
4 changes: 3 additions & 1 deletion packages/react-bootstrap-table2-example/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ColumnEventTable from 'examples/columns/column-event-table';
import ColumnHiddenTable from 'examples/columns/column-hidden-table';
import ColumnAttrsTable from 'examples/columns/column-attrs-table';
import DummyColumnTable from 'examples/columns/dummy-column-table';
import RowExpandWithFormattedDummyColumn from 'examples/columns/row-expand-with-formatted-dummy-column.js';

// work on header columns
import HeaderColumnFormatTable from 'examples/header-columns/column-format-table';
Expand Down Expand Up @@ -273,7 +274,8 @@ storiesOf('Work on Columns', module)
.add('Customize Column Class', () => <ColumnClassTable />)
.add('Customize Column Style', () => <ColumnStyleTable />)
.add('Customize Column HTML attribute', () => <ColumnAttrsTable />)
.add('Dummy Column', () => <DummyColumnTable />);
.add('Dummy Column', () => <DummyColumnTable />)
.add('Row Expand with Dummy Column Formatter', () => <RowExpandWithFormattedDummyColumn />);

storiesOf('Work on Header Columns', module)
.addDecorator(bootstrapStyle())
Expand Down
4 changes: 2 additions & 2 deletions packages/react-bootstrap-table2/src/row/aggregate-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
this.props.selectable !== nextProps.selectable ||
this.shouldUpdatedBySelfProps(nextProps)
) {
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);
return true;
}
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);

return this.shouldUpdateRowContent;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/react-bootstrap-table2/src/row/should-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ export default ExtendBase =>
return this.shouldUpdateByCellEditing(nextProps) ||
this.shouldUpdatedByNormalProps(nextProps);
}

shouldRowContentUpdate(nextProps) {
return this.shouldUpdateChild(nextProps) ||
this.shouldUpdateByColumnsForSimpleCheck(nextProps);
}
};
3 changes: 1 addition & 2 deletions packages/react-bootstrap-table2/src/row/simple-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class SimpleRow extends shouldUpdater(eventDelegater(Component)) {

shouldComponentUpdate(nextProps) {
this.shouldUpdateRowContent = false;
this.shouldUpdateRowContent =
this.shouldUpdateChild(nextProps) || this.shouldUpdateByColumnsForSimpleCheck(nextProps);
this.shouldUpdateRowContent = this.shouldRowContentUpdate(nextProps);
if (this.shouldUpdateRowContent) return true;

return this.shouldUpdatedBySelfProps(nextProps);
Expand Down