我为复选框输入创建了单元格渲染器,但当我单击复选框时,它会更改单元格内的值,但不会更改单元格上的值。
参见Plunker示例:Plunkerrefresh
方法应该在更改时调用,但无论如何它不是。onCellClicked
无论我如何单击复选框,函数都返回相同的值。
我尝试用两个可能的值cellEditor: 'agRichSelect'
和true
进行false
操作,效果很好,但我需要复选框。
他有什么想法!
最佳答案
First,要跟踪ngModel
的更改,需要使用(ngModelChange)
而不是(onChange)
。
其次,不应该使用params.value
进行ngModel
绑定,params
-是grid
的一部分,所以要避免混合,并单独保存。
Third,在refresh
函数内部,不应更新cellRenderer
,params
函数内部用于refresh
。
// Mandatory - Get the cell to refresh. Return true if the refresh succeeded, otherwise return false.
// If you return false, the grid will remove the component from the DOM and create
// a new component in its place with the new values.
refresh(params: any): boolean;
第四,如果要更新
grid
中的值,应该使用cellRenderer
接口,而不是ICellEditorComp
(ICellRendererComp
和ICellRendererAngularComp
在ICellEditorAngularComp
情况下)第五,您忘记在
Angular
中设置复选框字段editable: true
最后一个-您刚刚创建了一个复选框(超出
columnDefs
范围),它看起来像一个工作示例,但实际上不是。如果
grid
,您需要了解完整的编辑过程,因此只需检查这里有关cell rendering、cell editing和更多的详细信息。以及here您可以看到exactly自定义复选框渲染器将如何工作:
function booleanCellRenderer(params) {
var valueCleaned = booleanCleaner(params.value);
if (valueCleaned === true) {
return "<span title='true' class='ag-icon ag-icon-tick content-icon'></span>";
} else if (valueCleaned === false) {
return "<span title='false' class='ag-icon ag-icon-cross content-icon'></span>";
} else if (params.value !== null && params.value !== undefined) {
return params.value.toString();
} else {
return null;
}
}