Ag grid 为什么在onGridReady中设置了ag网格清除过滤器
我遇到了一个奇怪的行为,如果我在onGridReady事件中设置了一个过滤器模型,它会在之后被删除。我已经记录了filterChanged事件,当我设置过滤器时,我看到它被调用,但它再也不会被调用,但是过滤器在没有过滤器更改事件的情况下被清除。当我使用社区时,我没有经历过这种情况,但当我升级到enterprise并开始使用setFilter时,这种情况就开始发生了。有什么想法吗Ag grid 为什么在onGridReady中设置了ag网格清除过滤器,ag-grid,ag-grid-angular,Ag Grid,Ag Grid Angular,我遇到了一个奇怪的行为,如果我在onGridReady事件中设置了一个过滤器模型,它会在之后被删除。我已经记录了filterChanged事件,当我设置过滤器时,我看到它被调用,但它再也不会被调用,但是过滤器在没有过滤器更改事件的情况下被清除。当我使用社区时,我没有经历过这种情况,但当我升级到enterprise并开始使用setFilter时,这种情况就开始发生了。有什么想法吗 onGridReady(params: ICellRendererParams): void {
onGridReady(params: ICellRendererParams): void {
this.gridApi = params.api
this.gridApi.sizeColumnsToFit()
this.resetDefaults()
window.addEventListener('resize', function() {
setTimeout(function() {
params.api.sizeColumnsToFit()
})
})
}
resetDefaults(): void {
this.gridApi.setFilterModel({
ColorStatus: {
filterType: 'set',
values: [ColorStatus.red.toString(), ColorStatus.yellow.toString()]
}
})
this.gridApi.onFilterChanged(); //I've tried with and without this line
}
奇怪的是,当我在onGridReady中设置排序时,排序模型没有受到影响,只有过滤器模型被清除。
同时,我将resetDefaults()移到了onFirstDataRendered事件,但这并不理想,因为用户将在它之前的一段时间内看到所有数据
获取筛选。尝试以下方法,而不是使用
gridApi.setFilterModel
设置filterModel
colId
获取列的筛选器实例(在定义ColDef
时进行设置)
setModel
使用过滤器实例//定义过滤器模型
常数过滤器模型={
颜色状态:{
filterType:'set',
值:[ColorStatus.red.toString(),ColorStatus.yellow.toString()]
}
};
const filternistance=this.gridApi.getfilternistance(colId);// 我的同事发现,将newRowsAction:“keep”
添加到相关列的filterParams中可以解决问题使用filter实例中的setModel似乎也有同样的问题,不幸的是,您能给出一个重发该问题的提示吗?
// define filterModel
const filterModel = {
ColorStatus: {
filterType: 'set',
values: [ColorStatus.red.toString(), ColorStatus.yellow.toString()]
}
};
const filterInstance = this.gridApi.getFilterInstance(colId); // <- ColorStatus column columnId
// you need to set it inside ColDef for this column
filterInstance.setModel(filterModel);