This commit is contained in:
AllenFang 2018-10-28 14:32:11 +08:00
parent 569c22ba49
commit f1f4bd784d
3 changed files with 17 additions and 9 deletions

View File

@ -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);
};
}

View File

@ -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) {

View File

@ -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;