ag-grid-enterprise
Version:
ag-Grid Enterprise Features
93 lines (77 loc) • 3.25 kB
text/typescript
import {
Autowired,
ColumnController,
EventService,
Context,
LoggerFactory,
DragAndDropService,
GridOptionsWrapper,
PostConstruct,
Utils,
Events,
Column,
ColumnRowGroupChangeRequestEvent,
ColumnApi,
GridApi
} from "ag-grid-community/main";
import {BaseDropZonePanel} from "../dropZone/baseDropZonePanel";
export class RowGroupDropZonePanel extends BaseDropZonePanel {
private columnController:ColumnController;
private eventService:EventService;
private gridOptionsWrapper:GridOptionsWrapper;
private context:Context;
private loggerFactory:LoggerFactory;
private dragAndDropService:DragAndDropService;
private columnApi: ColumnApi;
private gridApi: GridApi;
constructor(horizontal:boolean) {
super(horizontal, false, 'row-group');
}
private passBeansUp():void {
super.setBeans({
gridOptionsWrapper: this.gridOptionsWrapper,
eventService: this.eventService,
context: this.context,
loggerFactory: this.loggerFactory,
dragAndDropService: this.dragAndDropService
});
let localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc();
let emptyMessage = localeTextFunc('rowGroupColumnsEmptyMessage', 'Drag here to set row groups');
let title = localeTextFunc('groups', 'Row Groups');
super.init({
dragAndDropIcon: DragAndDropService.ICON_GROUP,
icon: Utils.createIconNoSpan('rowGroupPanel', this.gridOptionsWrapper, null),
emptyMessage: emptyMessage,
title: title
});
this.addDestroyableEventListener(this.eventService, Events.EVENT_COLUMN_ROW_GROUP_CHANGED, this.refreshGui.bind(this));
}
protected isColumnDroppable(column: Column): boolean {
if (this.gridOptionsWrapper.isFunctionsReadOnly()) { return false; }
// we never allow grouping of secondary columns
if (!column.isPrimary()) { return false; }
let columnGroupable = column.isAllowRowGroup();
let columnNotAlreadyGrouped = !column.isRowGroupActive();
return columnGroupable && columnNotAlreadyGrouped;
}
protected updateColumns(columns:Column[]) {
if (this.gridOptionsWrapper.isFunctionsPassive()) {
let event: ColumnRowGroupChangeRequestEvent = {
type: Events.EVENT_COLUMN_ROW_GROUP_CHANGE_REQUEST,
columns: columns,
api: this.gridApi,
columnApi: this.columnApi
};
this.eventService.dispatchEvent(event);
} else {
this.columnController.setRowGroupColumns(columns, "toolPanelUi");
}
}
protected getIconName(): string {
return this.isPotentialDndColumns() ? DragAndDropService.ICON_GROUP : DragAndDropService.ICON_NOT_ALLOWED;
}
protected getExistingColumns(): Column[] {
return this.columnController.getRowGroupColumns();
}
}