javascript - 在对话框中渲染过滤器组件
问题描述
我正在尝试在 a 中渲染过滤器mat-dialog
,我发现它可以正确渲染,但在功能上不可用,我不确定这是否是正确的方法。
这是代码
这是我创建和打开对话框的方式:
public lol(colDef: ColDef): void {
console.log(colDef);
this.gridApi?.getFilterInstance(colDef.field, (foo) => {
console.log(foo.getModel());
foo.setModel(foo.getModel());
this.dialog.open(FilterWrapperDialogComponent, {
data: {
filterHtml: foo.getGui()
},
panelClass: 'ag-custom-component-popup'
}).afterClosed().subscribe((applyOrNot) => {
if (applyOrNot) {
this.gridApi.onFilterChanged();
console.log(foo.getModel());
}
});
})
}
对话内容:
<mat-dialog-content>
<div class="ag-theme-material ag-custom-component-popup" [innerHTML]="data.filterHtml?.innerHTML | safeUrl: 'html' "></div>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button i18n [mat-dialog-close]="true" color="primary">Apply</button>
</mat-dialog-actions>
它可以正确呈现,但会失去功能。
我的目标是在不实际添加到 ag-grid 表的情况下设置过滤器,只需通过对话框和 ag-grid API。
解决方案
问题是我使用的是[innerHTML]="data.filterHtml?.innerHTML | safeUrl: 'html' "
出于安全原因(XSS)剥离任何功能。解决方案是给 div 一个 id 并从getGui()
对话框 HTML:
<mat-dialog-content>
<div class="ag-theme-material ag-custom-component-popup" id="second"></div>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button i18n [mat-dialog-close]="true" color="primary">Apply</button>
</mat-dialog-actions>
将 HTML 附加到 div;对话逻辑:
import { Component, ChangeDetectionStrategy, Inject, AfterViewInit } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'app-filter-wrapper-dialog',
templateUrl: './filter-wrapper-dialog.component.html',
styleUrls: ['./filter-wrapper-dialog.component.scss'],
changeDetection: ChangeDetectionStrategy.Default
})
export class FilterWrapperDialogComponent implements AfterViewInit {
constructor(
@Inject(MAT_DIALOG_DATA) public data: any
) {}
ngAfterViewInit(): void {
document.querySelector('#second').appendChild((this.data.filterHtml as HTMLElement));
}
}
通过这些更改,我能够正确且功能性地渲染过滤器。
推荐阅读
- wordpress - Codepen 集成到 Wordpress
- r - 如何通过仅选择原始列的偶数行来创建另一列?
- mysql - MySQL“手工”分区
- grails - Grails 3 PluginDescriptor 配置
- realm - 在 Payara 中使用具有不同基于文件的领域的 @RunAs
- html - HTML5 自定义元素和属性
- reactjs - 将图像作为道具传递
- ios - iOS 13.4 中的 MPMusicPlayerController.applicationQueuePlayer 错误
- assembly - 无法连续两次从变量中输出协处理器浮点数
- c++ - pop_back 中的垃圾值,C++ 中的双向链表