Skip to content

Commit 7d28d46

Browse files
committed
enhance footer event
1 parent 16128e7 commit 7d28d46

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

docs/columns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ It's also available to custom via a callback function:
666666
{
667667
// omit...
668668
footerEvents: {
669-
onClick: e => { ... }
669+
onClick: (e, column, columnIndex) => { ... }
670670
}
671671
}
672672
```

packages/react-bootstrap-table2-example/examples/footer/column-event-table.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const columns = [{
1212
dataField: 'id',
1313
text: 'Product ID',
1414
footerEvents: {
15-
onClick: () => alert('Click on Product ID footer column')
15+
onClick: (e, column, columnIndex) => alert(`Click on Product ID header column, columnIndex: ${columnIndex}`)
1616
},
1717
footer: 'Footer 1'
1818
}, {
@@ -32,7 +32,7 @@ const columns = [{
3232
dataField: 'id',
3333
text: 'Product ID',
3434
footerEvents: {
35-
onClick: () => alert('Click on Product ID footer column')
35+
onClick: (e, column, columnIndex) => alert('Click on Product ID footer column')
3636
},
3737
footer: 'Footer 1'
3838
}, {

packages/react-bootstrap-table2/src/footer-cell.js

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,61 @@ import cs from 'classnames';
44
import PropTypes from 'prop-types';
55

66
import _ from './utils';
7+
import eventDelegater from './cell-event-delegater';
78

8-
const FooterCell = (props) => {
9-
const { index, column, columnData } = props;
9+
class FooterCell extends eventDelegater(React.Component) {
10+
render() {
11+
const { index, column, columnData } = this.props;
1012

11-
const {
12-
footer,
13-
footerTitle,
14-
footerAlign,
15-
footerFormatter,
16-
footerEvents,
17-
footerClasses,
18-
footerStyle,
19-
footerAttrs
20-
} = column;
13+
const {
14+
footer,
15+
footerTitle,
16+
footerAlign,
17+
footerFormatter,
18+
footerEvents,
19+
footerClasses,
20+
footerStyle,
21+
footerAttrs
22+
} = column;
2123

22-
const cellAttrs = {
23-
...(_.isFunction(footerAttrs) ? footerAttrs(column, index) : footerAttrs),
24-
...footerEvents
25-
};
24+
const delegateEvents = this.delegate(footerEvents);
25+
const cellAttrs = {
26+
...(_.isFunction(footerAttrs) ? footerAttrs(column, index) : footerAttrs),
27+
...delegateEvents
28+
};
2629

27-
let text = '';
28-
if (_.isString(footer)) {
29-
text = footer;
30-
} else if (_.isFunction(footer)) {
31-
text = footer(columnData, column, index);
32-
}
3330

34-
let cellStyle = {};
35-
const cellClasses = _.isFunction(footerClasses) ? footerClasses(column, index) : footerClasses;
31+
let text = '';
32+
if (_.isString(footer)) {
33+
text = footer;
34+
} else if (_.isFunction(footer)) {
35+
text = footer(columnData, column, index);
36+
}
3637

37-
if (footerStyle) {
38-
cellStyle = _.isFunction(footerStyle) ? footerStyle(column, index) : footerStyle;
39-
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
40-
}
38+
let cellStyle = {};
39+
const cellClasses = _.isFunction(footerClasses) ? footerClasses(column, index) : footerClasses;
4140

42-
if (footerTitle) {
43-
cellAttrs.title = _.isFunction(footerTitle) ? footerTitle(column, index) : text;
44-
}
41+
if (footerStyle) {
42+
cellStyle = _.isFunction(footerStyle) ? footerStyle(column, index) : footerStyle;
43+
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
44+
}
4545

46-
if (footerAlign) {
47-
cellStyle.textAlign = _.isFunction(footerAlign) ? footerAlign(column, index) : footerAlign;
48-
}
46+
if (footerTitle) {
47+
cellAttrs.title = _.isFunction(footerTitle) ? footerTitle(column, index) : text;
48+
}
4949

50-
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
51-
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
50+
if (footerAlign) {
51+
cellStyle.textAlign = _.isFunction(footerAlign) ? footerAlign(column, index) : footerAlign;
52+
}
5253

53-
const children = footerFormatter ? footerFormatter(column, index) : text;
54+
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
55+
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
5456

55-
return React.createElement('th', cellAttrs, children);
56-
};
57+
const children = footerFormatter ? footerFormatter(column, index) : text;
58+
59+
return React.createElement('th', cellAttrs, children);
60+
}
61+
}
5762

5863
FooterCell.propTypes = {
5964
columnData: PropTypes.array,

0 commit comments

Comments
 (0)