mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
fix #621
This commit is contained in:
parent
569c22ba49
commit
f1f4bd784d
@ -7,17 +7,16 @@ const events = [
|
||||
];
|
||||
|
||||
export default ExtendBase =>
|
||||
class RowEventDelegater extends ExtendBase {
|
||||
class CellEventDelegater extends ExtendBase {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.clickNum = 0;
|
||||
this.createDefaultEventHandler = this.createDefaultEventHandler.bind(this);
|
||||
}
|
||||
|
||||
createDefaultEventHandler(cb) {
|
||||
return (e) => {
|
||||
const { row, rowIndex } = this.props;
|
||||
cb(e, row, rowIndex);
|
||||
const { column, columnIndex } = this.props;
|
||||
cb(e, column, columnIndex);
|
||||
};
|
||||
}
|
||||
|
||||
5
packages/react-bootstrap-table2/src/cell.js
vendored
5
packages/react-bootstrap-table2/src/cell.js
vendored
@ -2,9 +2,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import eventDelegater from './cell-event-delegater';
|
||||
import _ from './utils';
|
||||
|
||||
class Cell extends Component {
|
||||
class Cell extends eventDelegater(Component) {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleEditingCell = this.handleEditingCell.bind(this);
|
||||
@ -73,7 +74,7 @@ class Cell extends Component {
|
||||
formatter,
|
||||
formatExtraData
|
||||
} = column;
|
||||
const attrs = { ...rest };
|
||||
const attrs = this.delegate({ ...rest });
|
||||
let content = column.isDummyField ? null : _.get(row, dataField);
|
||||
|
||||
if (formatter) {
|
||||
|
||||
@ -50,13 +50,21 @@ export default class RowPureContent extends React.Component {
|
||||
// render cell
|
||||
let cellTitle;
|
||||
let cellStyle = {};
|
||||
const cellAttrs = {
|
||||
let cellAttrs = {
|
||||
..._.isFunction(column.attrs)
|
||||
? column.attrs(content, row, rowIndex, index)
|
||||
: column.attrs,
|
||||
...column.events
|
||||
: column.attrs
|
||||
};
|
||||
|
||||
if (column.events) {
|
||||
const events = Object.assign({}, column.events);
|
||||
Object.keys(Object.assign({}, column.events)).forEach((key) => {
|
||||
const originFn = events[key];
|
||||
events[key] = (...rest) => originFn(...rest, row, rowIndex);
|
||||
});
|
||||
cellAttrs = { ...cellAttrs, ...events };
|
||||
}
|
||||
|
||||
const cellClasses = _.isFunction(column.classes)
|
||||
? column.classes(content, row, rowIndex, index)
|
||||
: column.classes;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user