你可以重写 getContextMenuItems里面的函数gridOptions
getContextMenuItems: this.getCustomContextMenuItems.bind(this)
getCustomContextMenuItems(params:GetContextMenuItemsParams) : MenuItemDef {
let contextMenu: MenuItemDef = [];
//... custom export just for info ...
contextMenu.push({
name:"Export",
subMenu:[
{
name: "CSV Export (.csv)",
action: () => params.api.exportDataAsCsv()
},
{
name: "Excel Export (.xlsx)",
action: () => params.api.exportDataAsExcel()
},
{
name: "Excel Export (.xml)",
action: () => params.api.exportDataAsExcel({exportMode:"xml"})
}
]
})
return contextMenu;
}
Run Code Online (Sandbox Code Playgroud)
要在工具面板中添加自己的逻辑,您必须:
创建一个自定义的
toolPanelComponent,在这个组件中,您只需要执行exportDataAsCsv()orexportDataAsExcel()。
import {Component, ViewChild, ViewContainerRef} from "@angular/core";
import {IToolPanel, IToolPanelParams} from "ag-grid-community";
@Component({
selector: 'custom-panel',
template: `<button (click)="handleExportClick()">Export</button>`
})
export class CustomToolPanelComponent implements IToolPanel {
private params: IToolPanelParams;
agInit(params: IToolPanelParams): void {
this.params = params;
}
handleExportClick(){
this.params.api.exportDataAsCsv()
}
}
Run Code Online (Sandbox Code Playgroud)
添加
CustomToolPanelComponent到AgGridModule.withComponents您的初始化AppModule(或注入的任何模块 ag-grid)
@NgModule({
imports: [
...
AgGridModule.withComponents([CustomToolPanelComponent])
],
declarations: [AppComponent, CustomToolPanelComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
在其中添加
CustomToolPanelComponent引用frameworkComponentsgridOptions
this.frameworkComponents = { customToolPanel: CustomToolPanelComponent};
Run Code Online (Sandbox Code Playgroud)
将
CustomToolPanelComponent引用(在 中定义frameworkComponents)添加到sideBar.toolPanels数组
this.sideBar = {
toolPanels: [
...
{
id: "customPanel",
labelDefault: "Custom Panel",
labelKey: "customPanel",
iconKey: "custom-panel",
toolPanel: "customToolPanel"
}
]
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5124 次 |
| 最近记录: |