问题
I am using ag-grid with angular 8 with an enterprise license. For some reason, the default "copy", "copy with headers" context menu items are not available. Only the "Export" item is showing up. Other enterprise features are working fine, but I can't seem to figure out how to enable "copy".
I'm not sure what I can try next, I've tried using different imports, disabling features, ...
The ag-grid-angular tag:
<ag-grid-angular
#agGrid
style="width: 800px; height: 500px;"
class="ag-theme-balham"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
rowGroupPanelShow="always"
[modules]="modules"
[sideBar]="true"
rowSelection="multiple"
enableRangeSelection="true"
setSuppressClipboardPaste="false"
[suppressDragLeaveHidesColumns]="true"
[suppressMakeColumnVisibleAfterUnGroup]="true"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
></ag-grid-angular>
The test component file looks like this:
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AllModules , Module} from "@ag-grid-enterprise/all-modules";
import "@ag-grid-enterprise/core";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
private gridApi ;
private gridColumnApi ;
private columnDefs;
private defaultColDef;
private rowData;
public modules: Module[] = AllModules;
constructor(private http: HttpClient) {
this.columnDefs = [
{
field: "athlete",
width: 150,
filter: "agTextColumnFilter"
},
{
field: "age",
width: 90
},
{
field: "country",
width: 120
},
{
field: "year",
width: 90
},
{
field: "date",
width: 110
},
{
field: "gold",
width: 100
},
{
field: "silver",
width: 100
},
{
field: "bronze",
width: 100
},
{
field: "total",
width: 100
}
];
this.defaultColDef = {
enableValue: true,
enableRowGroup: true,
enablePivot: true,
sortable: true,
filter: true,
};
}
onGridReady(params) {
this.gridApi = params.api;
this.gridApi.setSuppressClipboardPaste = false;
this.gridColumnApi = params.columnApi;
this.http
.get("https://raw.githubusercontent.com/ag-grid/ag-grid/master/packages/ag-grid-docs/src/olympicWinners.json")
.subscribe(data => {
this.rowData = data;
});
}
}
I'm not sure if the following is related, but I'll add it as extra info: when I try to bind the enterprise modules "AllModules" to the ag-angular-grid HTML, some features stop working (like the sidebar) and I get the browser error:
ag-Grid: unable to use Column Tool Panel as module @ag-grid-enterprise/column-tool-panel is not present. You need to load the module with: import "@ag-grid-enterprise/column-tool-panel"
回答1:
Right, so apparently I've been using the wrong package for the ag-grid-angular component.
In my module file I was using:
import { AgGridModule } from 'ag-grid-angular';
switching to the following package made the whole thing work smooth as butter:
import { AgGridModule } from '@ag-grid-community/angular';
来源:https://stackoverflow.com/questions/59837146/ag-grid-angular-copy-menu-option-not-available