mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
commit
643b9bca5f
188
packages/react-bootstrap-table2-example/examples/columns/row-expand-with-formatted-dummy-column.js
vendored
Normal file
188
packages/react-bootstrap-table2-example/examples/columns/row-expand-with-formatted-dummy-column.js
vendored
Normal file
@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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';
|
||||
@ -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())
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -48,4 +48,9 @@ export default ExtendBase =>
|
||||
return this.shouldUpdateByCellEditing(nextProps) ||
|
||||
this.shouldUpdatedByNormalProps(nextProps);
|
||||
}
|
||||
|
||||
shouldRowContentUpdate(nextProps) {
|
||||
return this.shouldUpdateChild(nextProps) ||
|
||||
this.shouldUpdateByColumnsForSimpleCheck(nextProps);
|
||||
}
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user