只是为了提供更广泛的背景 - 我最终的目标是通过"同步"来增强可编辑的Cell。图标如果与后端同步。
我继续尝试将自定义道具添加到特定的可编辑单元格,以指示syncedWithBackEnd = true/false
,然后使用自定义格式化程序来有条件地添加样式(如果与DB道具同步是 true )。
问题,我未能将此自定义道具传递给Cell实例
到目前为止已经尝试过:
提供对Formatter的回调并从外部调用它。没有办法在Formatter实例上调用该函数(附加到特定单元格)
将道具设为handleRowUpdated
逻辑的一部分。设置自定义道具但它没有到达单元格:
var rows = this.getRows();
...
// e.updated.customProp = "whatever" ---> fails to reach Cell
Object.assign(rows[e.rowIdx], e.updated);
this.setState({rows: rows});
有关如何实现这一目标的任何想法?
或者也许有一些显而易见的方法可以达到我完全错过的最终目标(必须提到我对React不熟悉并且对js一般都是新手)。
答案 0 :(得分:1)
当实际同步发生时(在想要更新自定义单元格之前)我假设它是通过回调完成的?如果是这样,那么执行远程ajax调用以更新值的回调可以更新this.state.rows.customProp(this.state.rows.whatever.customProp)并且一旦状态发生变化并假设你的getRows()从this.state.rows获得然后它将自动发生。更糟糕的情况是,您可能必须在更改状态值后添加对this.forceupdate()的调用。这是基于我听到的类似和有效的东西......
//column data inside constructor (could be a const outside component as well)
this.columnData = [
{
key: whatever,
name: whatever,
...
formatter: (props)=>(<div className={props.dependentValues.isSynced? "green-bg" : "")} onClick={(evt)=>this.clickedToggleButton} >{props.value}</div>),
getRowMetaData: (data)=>(data),
},
...
}
]
这是我的数据网格包装器组件中的回调函数......
//when a span
clickedToggleButton(evt, props){
//do remote ajax call we have an ajax wrapper util we created so pseudo code...
MyUtil.call(url, params, callback: (response)=>{
if(this.response.success){
let rows = this.state.rows;
let isFound = false;
for(let obj of rows){
if(obj.id==props.changedId){
obj.isSynced = true;
isFound = true;
break;
}
}
//not sure if this is needed or not...
if(isFound){ this.forceUpdate(); }
}
}
}
不确定这是否有帮助,但可能会开始