angular - 刷新页面后Ag网格行选择丢失
问题描述
我在 Angular 7.x 中使用 ag-grid。每当刷新页面时,它都会失去突出显示的行焦点。这似乎是 ag-grid 中的一个错误。
是否有任何解决方法,例如使用参数 ID 将最后选择的行焦点设置回网格。
解决方案
您需要将所选行存储在 localStorage 中:
window.onbeforeunload = (event) => {
localStorage.setItem("selectedRows", JSON.stringify(this.gridOptions.api.getSelectedRows()));
};
然后在刷新并在网格中设置数据之后,以编程方式重新选择您的行:
reSelect = (): void => {
const selectedRows = JSON.parse(localStorage.getItem("selectedRows"));
this.gridOptions.api.forEachNode((node: RowNode, index: number) => {
// adapt with you own unique role-id rule
const selectNode = selectedRows.some((row) => { return row.id === node.data.id; });
if (selectNode) {
node.setSelected(true, false);
}
});
};
推荐阅读
- mysql - 两个 sql 语句的计数(*),其中结果是另一个语句的子集
- python-3.x - Cornerplot - 如何找出所有直方图的 xlims?
- ckeditor - CKeditor 4.16.1 Standard-Issue with Paste from word button 没有以正确的样式、格式、编号的项目符号列表完全复制 ms word 内容
- java - Spring boot Junit Test ResttemplateBuilder 构建方法给出空点异常
- touchgfx - 如何在 touchGFX 中为屏幕启动客户价值
- javascript - Bootstrap 5 - Carousel 不会滑动到下一个图像 - 从 bootstrap 4 升级到 bootstrap 5
- amazon-web-services - AWS 中的 Elastic Beanstalk 子域 CNAME 记录在哪里,以及如何向其中添加 SSL?
- laravel-8 - 如何在 Laravel 8 中创建临时表
- mfc - MFC/BCGP:将 DDX 与保持 BS_GROUPBOX 样式和 Button 类的控件一起使用?
- azure - 连接到 Azure 门户时重定向到另一个帐户的 MFA