mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
refine expand row consumer
This commit is contained in:
parent
9d4acaedd1
commit
7f7deff37f
38
packages/react-bootstrap-table2/src/body.js
vendored
38
packages/react-bootstrap-table2/src/body.js
vendored
@ -7,10 +7,10 @@ import PropTypes from 'prop-types';
|
|||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
import Row from './row';
|
import Row from './row';
|
||||||
import RowAggregator from './row-aggregator';
|
import RowAggregator from './row-aggregator';
|
||||||
import ExpandRow from './row-expand/expand-row';
|
|
||||||
import RowSection from './row-section';
|
import RowSection from './row-section';
|
||||||
import Const from './const';
|
import Const from './const';
|
||||||
import bindSelection from './row-selection/row-binder';
|
import bindSelection from './row-selection/row-binder';
|
||||||
|
import bindExpansion from './row-expand/row-binder';
|
||||||
|
|
||||||
const Body = (props) => {
|
const Body = (props) => {
|
||||||
const {
|
const {
|
||||||
@ -40,10 +40,13 @@ const Body = (props) => {
|
|||||||
let RowComponent = Row;
|
let RowComponent = Row;
|
||||||
const nonEditableRows = cellEdit.nonEditableRows || [];
|
const nonEditableRows = cellEdit.nonEditableRows || [];
|
||||||
const selectRowEnabled = selectRow.mode !== Const.ROW_SELECT_DISABLED;
|
const selectRowEnabled = selectRow.mode !== Const.ROW_SELECT_DISABLED;
|
||||||
const expandRowEnabled = !!expandRow;
|
const expandRowEnabled = !!expandRow.renderer;
|
||||||
|
|
||||||
|
if (expandRowEnabled) {
|
||||||
|
RowComponent = bindExpansion(RowAggregator, visibleColumnSize);
|
||||||
|
}
|
||||||
if (selectRowEnabled) {
|
if (selectRowEnabled) {
|
||||||
RowComponent = bindSelection(RowAggregator);
|
RowComponent = bindSelection(expandRowEnabled ? RowComponent : RowAggregator);
|
||||||
}
|
}
|
||||||
|
|
||||||
content = data.map((row, index) => {
|
content = data.map((row, index) => {
|
||||||
@ -55,12 +58,9 @@ const Body = (props) => {
|
|||||||
const classes = (_.isFunction(rowClasses) ? rowClasses(row, index) : rowClasses);
|
const classes = (_.isFunction(rowClasses) ? rowClasses(row, index) : rowClasses);
|
||||||
|
|
||||||
// refine later
|
// refine later
|
||||||
const expanded = expandRowEnabled && expandRow.expanded.includes(key);
|
const result =
|
||||||
|
|
||||||
// refine later
|
|
||||||
const result = [
|
|
||||||
selectRowEnabled || expandRowEnabled ?
|
selectRowEnabled || expandRowEnabled ?
|
||||||
<RowComponent
|
(<RowComponent
|
||||||
key={ key }
|
key={ key }
|
||||||
row={ row }
|
row={ row }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
@ -70,10 +70,10 @@ const Body = (props) => {
|
|||||||
className={ classes }
|
className={ classes }
|
||||||
attrs={ attrs }
|
attrs={ attrs }
|
||||||
cellEdit={ cellEdit }
|
cellEdit={ cellEdit }
|
||||||
selectRowEnabled={ selectRowEnabled }
|
selectRow={ selectRow }
|
||||||
expandRowEnabled={ expandRowEnabled }
|
expandRow={ expandRow }
|
||||||
/> :
|
/>) :
|
||||||
<RowComponent
|
(<RowComponent
|
||||||
key={ key }
|
key={ key }
|
||||||
row={ row }
|
row={ row }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
@ -84,19 +84,7 @@ const Body = (props) => {
|
|||||||
style={ style }
|
style={ style }
|
||||||
className={ classes }
|
className={ classes }
|
||||||
attrs={ attrs }
|
attrs={ attrs }
|
||||||
/>
|
/>);
|
||||||
];
|
|
||||||
|
|
||||||
if (expanded) {
|
|
||||||
result.push((
|
|
||||||
<ExpandRow
|
|
||||||
key={ `${key}-expanding` }
|
|
||||||
colSpan={ visibleColumnSize }
|
|
||||||
>
|
|
||||||
{ expandRow.renderer(row) }
|
|
||||||
</ExpandRow>
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -147,7 +147,7 @@ BootstrapTable.propTypes = {
|
|||||||
selectionHeaderRenderer: PropTypes.func
|
selectionHeaderRenderer: PropTypes.func
|
||||||
}),
|
}),
|
||||||
expandRow: PropTypes.shape({
|
expandRow: PropTypes.shape({
|
||||||
renderer: PropTypes.func.isRequired,
|
renderer: PropTypes.func,
|
||||||
expanded: PropTypes.array,
|
expanded: PropTypes.array,
|
||||||
onExpand: PropTypes.func,
|
onExpand: PropTypes.func,
|
||||||
onExpandAll: PropTypes.func,
|
onExpandAll: PropTypes.func,
|
||||||
@ -156,9 +156,6 @@ BootstrapTable.propTypes = {
|
|||||||
expandColumnRenderer: PropTypes.func,
|
expandColumnRenderer: PropTypes.func,
|
||||||
expandHeaderColumnRenderer: PropTypes.func
|
expandHeaderColumnRenderer: PropTypes.func
|
||||||
}),
|
}),
|
||||||
onRowExpand: PropTypes.func,
|
|
||||||
onAllRowExpand: PropTypes.func,
|
|
||||||
isAnyExpands: PropTypes.bool,
|
|
||||||
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
rowEvents: PropTypes.object,
|
rowEvents: PropTypes.object,
|
||||||
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
@ -191,7 +188,12 @@ BootstrapTable.defaultProps = {
|
|||||||
noDataIndication: null,
|
noDataIndication: null,
|
||||||
selectRow: {
|
selectRow: {
|
||||||
mode: Const.ROW_SELECT_DISABLED,
|
mode: Const.ROW_SELECT_DISABLED,
|
||||||
selected: []
|
selected: [],
|
||||||
|
hideSelectColumn: true
|
||||||
|
},
|
||||||
|
expandRow: {
|
||||||
|
renderer: undefined,
|
||||||
|
expanded: []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import _ from '../utils';
|
|||||||
import createDataContext from './data-context';
|
import createDataContext from './data-context';
|
||||||
import createSortContext from './sort-context';
|
import createSortContext from './sort-context';
|
||||||
import SelectionContext from './selection-context';
|
import SelectionContext from './selection-context';
|
||||||
import createRowExpandContext from './row-expand-context';
|
import RowExpandContext from './row-expand-context';
|
||||||
import remoteResolver from '../props-resolver/remote-resolver';
|
import remoteResolver from '../props-resolver/remote-resolver';
|
||||||
import { BootstrapContext } from './bootstrap';
|
import { BootstrapContext } from './bootstrap';
|
||||||
import dataOperator from '../store/operators';
|
import dataOperator from '../store/operators';
|
||||||
@ -26,7 +26,7 @@ const withContext = Base =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (props.expandRow) {
|
if (props.expandRow) {
|
||||||
this.RowExpandContext = createRowExpandContext(dataOperator);
|
this.RowExpandContext = RowExpandContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.cellEdit && props.cellEdit.createContext) {
|
if (props.cellEdit && props.cellEdit.createContext) {
|
||||||
@ -62,7 +62,6 @@ const withContext = Base =>
|
|||||||
searchProps,
|
searchProps,
|
||||||
sortProps,
|
sortProps,
|
||||||
paginationProps,
|
paginationProps,
|
||||||
expandProps
|
|
||||||
) => (
|
) => (
|
||||||
<Base
|
<Base
|
||||||
{ ...this.props }
|
{ ...this.props }
|
||||||
@ -71,7 +70,6 @@ const withContext = Base =>
|
|||||||
{ ...filterProps }
|
{ ...filterProps }
|
||||||
{ ...searchProps }
|
{ ...searchProps }
|
||||||
{ ...paginationProps }
|
{ ...paginationProps }
|
||||||
{ ...expandProps }
|
|
||||||
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -84,8 +82,7 @@ const withContext = Base =>
|
|||||||
filterProps,
|
filterProps,
|
||||||
searchProps,
|
searchProps,
|
||||||
sortProps,
|
sortProps,
|
||||||
paginationProps,
|
paginationProps
|
||||||
expandProps
|
|
||||||
) => (
|
) => (
|
||||||
<this.SelectionContext.Provider
|
<this.SelectionContext.Provider
|
||||||
{ ...baseProps }
|
{ ...baseProps }
|
||||||
@ -99,8 +96,7 @@ const withContext = Base =>
|
|||||||
filterProps,
|
filterProps,
|
||||||
searchProps,
|
searchProps,
|
||||||
sortProps,
|
sortProps,
|
||||||
paginationProps,
|
paginationProps
|
||||||
expandProps
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</this.SelectionContext.Provider>
|
</this.SelectionContext.Provider>
|
||||||
@ -121,19 +117,16 @@ const withContext = Base =>
|
|||||||
expandRow={ this.props.expandRow }
|
expandRow={ this.props.expandRow }
|
||||||
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
||||||
>
|
>
|
||||||
<this.RowExpandContext.Consumer>
|
{
|
||||||
{
|
base(
|
||||||
expandProps => base(
|
rootProps,
|
||||||
rootProps,
|
cellEditProps,
|
||||||
cellEditProps,
|
filterProps,
|
||||||
filterProps,
|
searchProps,
|
||||||
searchProps,
|
sortProps,
|
||||||
sortProps,
|
paginationProps
|
||||||
paginationProps,
|
)
|
||||||
expandProps
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
</this.RowExpandContext.Consumer>
|
|
||||||
</this.RowExpandContext.Provider>
|
</this.RowExpandContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,91 +1,90 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import dataOperator from '../store/operators';
|
||||||
|
|
||||||
export default (
|
const RowExpandContext = React.createContext();
|
||||||
dataOperator
|
|
||||||
) => {
|
|
||||||
const RowExpandContext = React.createContext();
|
|
||||||
|
|
||||||
class RowExpandProvider extends React.Component {
|
class RowExpandProvider extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
children: PropTypes.node.isRequired,
|
children: PropTypes.node.isRequired,
|
||||||
data: PropTypes.array.isRequired,
|
data: PropTypes.array.isRequired,
|
||||||
keyField: PropTypes.string.isRequired
|
keyField: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
state = { expanded: this.props.expandRow.expanded || [] };
|
state = { expanded: this.props.expandRow.expanded || [] };
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.expandRow) {
|
if (nextProps.expandRow) {
|
||||||
this.setState(() => ({
|
this.setState(() => ({
|
||||||
expanded: nextProps.expandRow.expanded || this.state.expanded
|
expanded: nextProps.expandRow.expanded || this.state.expanded
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
|
||||||
const { data, keyField, expandRow: { onExpand } } = this.props;
|
|
||||||
|
|
||||||
let currExpanded = [...this.state.expanded];
|
|
||||||
|
|
||||||
if (expanded) {
|
|
||||||
currExpanded.push(rowKey);
|
|
||||||
} else {
|
|
||||||
currExpanded = currExpanded.filter(value => value !== rowKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onExpand) {
|
|
||||||
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
|
|
||||||
onExpand(row, expanded, rowIndex, e);
|
|
||||||
}
|
|
||||||
this.setState(() => ({ expanded: currExpanded }));
|
|
||||||
}
|
|
||||||
|
|
||||||
handleAllRowExpand = (e, expandAll) => {
|
|
||||||
const {
|
|
||||||
data,
|
|
||||||
keyField,
|
|
||||||
expandRow: {
|
|
||||||
onExpandAll,
|
|
||||||
nonExpandable
|
|
||||||
}
|
|
||||||
} = this.props;
|
|
||||||
const { expanded } = this.state;
|
|
||||||
|
|
||||||
let currExpanded;
|
|
||||||
|
|
||||||
if (expandAll) {
|
|
||||||
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
|
|
||||||
} else {
|
|
||||||
currExpanded = expanded.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onExpandAll) {
|
|
||||||
onExpandAll(expandAll, dataOperator.getExpandedRows(data, keyField, currExpanded), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState(() => ({ expanded: currExpanded }));
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { data, keyField } = this.props;
|
|
||||||
return (
|
|
||||||
<RowExpandContext.Provider
|
|
||||||
value={ {
|
|
||||||
isAnyExpands: dataOperator.isAnyExpands(data, keyField, this.state.expanded),
|
|
||||||
expanded: this.state.expanded,
|
|
||||||
onRowExpand: this.handleRowExpand,
|
|
||||||
onAllRowExpand: this.handleAllRowExpand
|
|
||||||
} }
|
|
||||||
>
|
|
||||||
{ this.props.children }
|
|
||||||
</RowExpandContext.Provider>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
Provider: RowExpandProvider,
|
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
||||||
Consumer: RowExpandContext.Consumer
|
const { data, keyField, expandRow: { onExpand } } = this.props;
|
||||||
};
|
|
||||||
|
let currExpanded = [...this.state.expanded];
|
||||||
|
|
||||||
|
if (expanded) {
|
||||||
|
currExpanded.push(rowKey);
|
||||||
|
} else {
|
||||||
|
currExpanded = currExpanded.filter(value => value !== rowKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onExpand) {
|
||||||
|
const row = dataOperator.getRowByRowId(data, keyField, rowKey);
|
||||||
|
onExpand(row, expanded, rowIndex, e);
|
||||||
|
}
|
||||||
|
this.setState(() => ({ expanded: currExpanded }));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAllRowExpand = (e, expandAll) => {
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
keyField,
|
||||||
|
expandRow: {
|
||||||
|
onExpandAll,
|
||||||
|
nonExpandable
|
||||||
|
}
|
||||||
|
} = this.props;
|
||||||
|
const { expanded } = this.state;
|
||||||
|
|
||||||
|
let currExpanded;
|
||||||
|
|
||||||
|
if (expandAll) {
|
||||||
|
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
|
||||||
|
} else {
|
||||||
|
currExpanded = expanded.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onExpandAll) {
|
||||||
|
onExpandAll(expandAll, dataOperator.getExpandedRows(data, keyField, currExpanded), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState(() => ({ expanded: currExpanded }));
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { data, keyField } = this.props;
|
||||||
|
return (
|
||||||
|
<RowExpandContext.Provider
|
||||||
|
value={ {
|
||||||
|
...this.props.expandRow,
|
||||||
|
expanded: this.state.expanded,
|
||||||
|
isAnyExpands: dataOperator.isAnyExpands(data, keyField, this.state.expanded),
|
||||||
|
onRowExpand: this.handleRowExpand,
|
||||||
|
onAllRowExpand: this.handleAllRowExpand
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
{ this.props.children }
|
||||||
|
</RowExpandContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
Provider: RowExpandProvider,
|
||||||
|
Consumer: RowExpandContext.Consumer
|
||||||
};
|
};
|
||||||
|
|||||||
22
packages/react-bootstrap-table2/src/header.js
vendored
22
packages/react-bootstrap-table2/src/header.js
vendored
@ -1,16 +1,14 @@
|
|||||||
/* eslint react/require-default-props: 0 */
|
/* eslint react/require-default-props: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Const from './const';
|
|
||||||
|
|
||||||
import HeaderCell from './header-cell';
|
import HeaderCell from './header-cell';
|
||||||
import SelectionHeaderCell from './row-selection/selection-header-cell';
|
import SelectionHeaderCell from './row-selection/selection-header-cell';
|
||||||
import ExpandHeaderCell from './row-expand/expand-header-cell';
|
import ExpandHeaderCell from './row-expand/expand-header-cell';
|
||||||
import bindSelection from './row-selection/selection-header-cell-binder';
|
import bindSelection from './row-selection/selection-header-cell-binder';
|
||||||
|
import bindExpansion from './row-expand/expand-header-cell-binder';
|
||||||
|
|
||||||
const Header = (props) => {
|
const Header = (props) => {
|
||||||
const { ROW_SELECT_DISABLED } = Const;
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
className,
|
className,
|
||||||
columns,
|
columns,
|
||||||
@ -24,7 +22,12 @@ const Header = (props) => {
|
|||||||
bootstrap4
|
bootstrap4
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
let SelectionHeaderCellComp = () => {};
|
let SelectionHeaderCellComp = () => null;
|
||||||
|
let ExpansionHeaderCellComp = () => null;
|
||||||
|
|
||||||
|
if (expandRow.showExpandColumn) {
|
||||||
|
ExpansionHeaderCellComp = bindExpansion(ExpandHeaderCell);
|
||||||
|
}
|
||||||
|
|
||||||
if (selectRow) {
|
if (selectRow) {
|
||||||
SelectionHeaderCellComp = bindSelection(SelectionHeaderCell);
|
SelectionHeaderCellComp = bindSelection(SelectionHeaderCell);
|
||||||
@ -33,16 +36,9 @@ const Header = (props) => {
|
|||||||
return (
|
return (
|
||||||
<thead>
|
<thead>
|
||||||
<tr className={ className }>
|
<tr className={ className }>
|
||||||
|
<ExpansionHeaderCellComp />
|
||||||
{
|
{
|
||||||
(expandRow && expandRow.showExpandColumn)
|
!selectRow.hideSelectColumn ?
|
||||||
? <ExpandHeaderCell
|
|
||||||
onAllRowExpand={ expandRow.onAllRowExpand }
|
|
||||||
anyExpands={ expandRow.isAnyExpands }
|
|
||||||
renderer={ expandRow.expandHeaderColumnRenderer }
|
|
||||||
/> : null
|
|
||||||
}
|
|
||||||
{
|
|
||||||
(selectRow.mode !== ROW_SELECT_DISABLED && !selectRow.hideSelectColumn) ?
|
|
||||||
<SelectionHeaderCellComp /> : null
|
<SelectionHeaderCellComp /> : null
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export default class RowAggregator extends React.Component {
|
|||||||
if (expandRow && expandable) {
|
if (expandRow && expandable) {
|
||||||
expandRow.onRowExpand(key, !expanded, rowIndex, e);
|
expandRow.onRowExpand(key, !expanded, rowIndex, e);
|
||||||
}
|
}
|
||||||
if (selectable) {
|
if (selectRow.clickToSelect && selectable) {
|
||||||
selectRow.onRowSelect(key, !selected, rowIndex, e);
|
selectRow.onRowSelect(key, !selected, rowIndex, e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -79,22 +79,20 @@ export default class RowAggregator extends React.Component {
|
|||||||
cellEdit,
|
cellEdit,
|
||||||
selectRow,
|
selectRow,
|
||||||
expandRow,
|
expandRow,
|
||||||
|
expanded,
|
||||||
selected,
|
selected,
|
||||||
selectable,
|
selectable
|
||||||
expandRowEnabled
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const key = _.get(row, keyField);
|
const key = _.get(row, keyField);
|
||||||
const { hideSelectColumn } = selectRow;
|
const { hideSelectColumn, clickToSelect } = selectRow;
|
||||||
const { showExpandColumn } = expandRow || {};
|
const { showExpandColumn } = expandRow;
|
||||||
|
|
||||||
const nonEditableRows = cellEdit.nonEditableRows || [];
|
const nonEditableRows = cellEdit.nonEditableRows || [];
|
||||||
const editable = !(nonEditableRows.length > 0 && nonEditableRows.indexOf(key) > -1);
|
const editable = !(nonEditableRows.length > 0 && nonEditableRows.indexOf(key) > -1);
|
||||||
// const expandable = expandRowEnabled && !expandRow.nonExpandable.includes(key);
|
|
||||||
const expanded = expandRowEnabled && expandRow.expanded.includes(key);
|
|
||||||
|
|
||||||
const newAttrs = { ...attrs };
|
const newAttrs = { ...attrs };
|
||||||
if (selectRow.clickToSelect || expandRowEnabled) {
|
if (clickToSelect || !!expandRow.renderer) {
|
||||||
newAttrs.onClick = this.createClickEventHandler(attrs.onClick);
|
newAttrs.onClick = this.createClickEventHandler(attrs.onClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
packages/react-bootstrap-table2/src/row-expand/expand-header-cell-binder.js
vendored
Normal file
8
packages/react-bootstrap-table2/src/row-expand/expand-header-cell-binder.js
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ExpansionContext from '../contexts/row-expand-context';
|
||||||
|
|
||||||
|
export default Component => () => (
|
||||||
|
<ExpansionContext.Consumer>
|
||||||
|
{ expandRow => <Component { ...expandRow } /> }
|
||||||
|
</ExpansionContext.Consumer>
|
||||||
|
);
|
||||||
@ -3,11 +3,11 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
export default class SelectionHeaderCell extends Component {
|
export default class ExpansionHeaderCell extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
anyExpands: PropTypes.bool.isRequired,
|
isAnyExpands: PropTypes.bool.isRequired,
|
||||||
onAllRowExpand: PropTypes.func.isRequired,
|
onAllRowExpand: PropTypes.func.isRequired,
|
||||||
renderer: PropTypes.func
|
expandHeaderColumnRenderer: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -16,13 +16,13 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleCheckBoxClick(e) {
|
handleCheckBoxClick(e) {
|
||||||
const { anyExpands, onAllRowExpand } = this.props;
|
const { isAnyExpands, onAllRowExpand } = this.props;
|
||||||
|
|
||||||
onAllRowExpand(e, !anyExpands);
|
onAllRowExpand(e, !isAnyExpands);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { anyExpands, renderer } = this.props;
|
const { isAnyExpands, expandHeaderColumnRenderer } = this.props;
|
||||||
const attrs = {
|
const attrs = {
|
||||||
onClick: this.handleCheckBoxClick
|
onClick: this.handleCheckBoxClick
|
||||||
};
|
};
|
||||||
@ -30,9 +30,9 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
return (
|
return (
|
||||||
<th data-row-selection { ...attrs }>
|
<th data-row-selection { ...attrs }>
|
||||||
{
|
{
|
||||||
renderer ?
|
expandHeaderColumnRenderer ?
|
||||||
renderer({ isAnyExpands: anyExpands }) :
|
expandHeaderColumnRenderer({ isAnyExpands }) :
|
||||||
(anyExpands ? '(-)' : '(+)')
|
(isAnyExpands ? '(-)' : '(+)')
|
||||||
}
|
}
|
||||||
</th>
|
</th>
|
||||||
);
|
);
|
||||||
|
|||||||
35
packages/react-bootstrap-table2/src/row-expand/row-binder.js
vendored
Normal file
35
packages/react-bootstrap-table2/src/row-expand/row-binder.js
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import _ from '../utils';
|
||||||
|
import ExpandRow from './expand-row';
|
||||||
|
import ExpansionContext from '../contexts/row-expand-context';
|
||||||
|
|
||||||
|
export default (Component, visibleColumnSize) => {
|
||||||
|
const renderWithExpansion = (props, expandRow) => {
|
||||||
|
const key = _.get(props.row, props.keyField);
|
||||||
|
|
||||||
|
const expanded = expandRow.expanded.includes(key);
|
||||||
|
const expandable = !expandRow.nonExpandable || !expandRow.nonExpandable.includes(key);
|
||||||
|
|
||||||
|
return [
|
||||||
|
<Component
|
||||||
|
{ ...props }
|
||||||
|
key={ key }
|
||||||
|
expanded={ expanded }
|
||||||
|
expandable={ expandable }
|
||||||
|
expandRow={ { ...expandRow } }
|
||||||
|
/>,
|
||||||
|
expanded ? <ExpandRow
|
||||||
|
key={ `${key}-expanding` }
|
||||||
|
colSpan={ visibleColumnSize }
|
||||||
|
>
|
||||||
|
{ expandRow.renderer(props.row) }
|
||||||
|
</ExpandRow> : null
|
||||||
|
];
|
||||||
|
};
|
||||||
|
return props => (
|
||||||
|
<ExpansionContext.Consumer>
|
||||||
|
{ expandRow => renderWithExpansion(props, expandRow) }
|
||||||
|
</ExpansionContext.Consumer>
|
||||||
|
);
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user