如何访问ag-grid cell renderer函数内的类函数

时间:2017-04-14 16:52:37

标签: ag-grid ag-grid-react

class abc extends React.Component{
_handleClick(){
console.log("some API call and state change");
}
}

columndefs: [
        {headerName:'Label', field: 'label', width:130, pinned:'left', cellClass:'ag-cell-text-align-center', cellRenderer:linkRenderer},
        {headerName:'Received', field: 'receivedDate', width:130, cellClass:'ag-cell-text-align-center'},
]

function linkRenderer(){
return params.data.link ? `<span style=text-decoration:underline;color:blue;cursor:pointer onClick="this._handleClick()">${params.value}</span>`: params.value;
}

这告诉“this._handleClick不是函数” 那么,如何在linkRenederer中调用this._handleClick

1 个答案:

答案 0 :(得分:0)

我在您的代码中看到了几个语法问题。例如:style应该是一个对象。你不应该像那样使用onClick。尝试这样的事情:

<span 
    style={{ textDecoration: "underline", color: "blue", cursor: "pointer" }} 
    onClick={ this._handleClick }>
    {params.value}
</span>

还绑定构造函数中的方法

constructor(props){
    super(props);
    this._handleClick = this._handleClick.bind(this);
}