问题的解决方法是使用Angular Slickgrid的onCellChange
事件来强制更新提示框。以下是一个示例代码:
import { Component, OnInit } from '@angular/core';
import { AngularGridInstance, Column, FieldType, Formatters, GridOption } from 'angular-slickgrid';
@Component({
templateUrl: './my-component.html'
})
export class MyComponent implements OnInit {
columnDefinitions: Column[];
gridOptions: GridOption;
dataset: any[];
angularGrid: AngularGridInstance;
isGridInitialized = false;
ngOnInit(): void {
this.columnDefinitions = [
{ id: 'title', name: 'Title', field: 'title', width: 70 },
{ id: 'duration', name: 'Duration (days)', field: 'duration', width: 70, formatter: Formatters.decimal },
{ id: 'complete', name: '% Complete', field: 'percentComplete', minWidth: 90, formatter: Formatters.percentCompleteBar },
{ id: 'start', name: 'Start', field: 'start', minWidth: 60 },
{ id: 'finish', name: 'Finish', field: 'finish', minWidth: 60 },
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', minWidth: 60 }
];
this.gridOptions = {
enableCellNavigation: true,
enableColumnResize: true,
enableAutoResize: true
};
this.dataset = this.getData(500);
this.isGridInitialized = true;
}
angularGridReady(angularGrid: AngularGridInstance) {
this.angularGrid = angularGrid;
}
onCellChanged(event: any, args: any) {
// Force cell to redraw by triggering a cell change event
// This will cause the Tooltip to read from the updated value
this.angularGrid.grid.invalidate();
const cell = this.angularGrid.grid.getActiveCell();
this.angularGrid.grid.scrollCellIntoView(cell.row, cell.cell);
}
private getData(count: number) {
const process = [];
for (let i = 0; i < count; i++) {
const rand = Math.floor(Math.random() * 100);
process.push({
id: i,
title: 'Task ' + i,
duration: rand,
percentComplete: rand,
start: new Date(2009, 0, 1),
finish: new Date(2009, 0, 1),
effortDriven: i % 5 === 0
});
}
return process;
}
}
在模板中,将onCellChanged
函数作为onCellChange
事件的处理程序绑定到单元格上: