我正在使用ag网格使用Vue.js来显示一个表格。我有一个列的定义是这样的。
{
headerName: "Status",
field: "featureStatus",
width: 110,
editable: true,
cellEditor: "agSelectCellEditor ",
cellEditorParams: {
values: []
}
},
this.allFeatureStatusNames是一个计算变量,返回一个字符串数组。
allFeatureStatusNames: function() {
return this.allFeatureStatuses.map(status => status.name)
}
我在allFeatureStatuses上有一个监视器,我想在创建表格后更新cellEditorParams。
allFeatureStatuses: function() {
let colDef = this.columnDefs.find(col => col.headerName == "Status")
if (colDef) {
colDef.cellEditorParams = {
values: this.allFeatureStatusNames
}
}
this.gridColumnApi.refreshCells()
},
我的问题是,单元格编辑器从未更新。它总是空的。我如何在创建表格后刷新或更新cellEditorParams?
虽然用你的方法,问题可能是你的colDef对象没有得到更新,因为你正试图修改一个现有的对象,而创建一个新的colDef可能对你有用。
像下面这样的方法对我来说是可行的
cellEditorParams: this.getValues.bind(this);
getValues: function() {
let allowedVals = this.allFeatureStatusNames;
return { values : allowedVals};
}