@Input() label: string;
@Input() action: (rows: any[]) => any;
+ // When present, actions will be grouped by the provided label.
+ @Input() group: string;
+
// Optional: add a function that returns true or false.
// If true, this action will be disabled; if false
// (default behavior), the action will be enabled.
const action = new GridToolbarAction();
action.label = this.label;
action.action = this.action;
+ action.group = this.group;
action.disableOnRows = this.disableOnRows;
this.grid.context.toolbarActions.push(action);
<button class="dropdown-item" (click)="performAction(action)"
*ngFor="let action of gridContext.toolbarActions"
[disabled]="shouldDisableAction(action)">
- <span class="ml-2">{{action.label}}</span>
+ <ng-container *ngIf="action.isGroup">
+ <span class="ml-2 font-weight-bold font-italic">{{action.label}}</span>
+ </ng-container>
+ <ng-container *ngIf="action.group && !action.isGroup">
+ <!-- grouped entries are indented -->
+ <span class="ml-4">{{action.label}}</span>
+ </ng-container>
+ <ng-container *ngIf="!action.group && !action.isGroup">
+ <span class="ml-2">{{action.label}}</span>
+ </ng-container>
</button>
</div>
</div>
@Input() colWidthConfig: GridColumnWidthComponent;
@Input() gridPrinter: GridPrintComponent;
+ renderedGroups: {[group: string]: boolean};
+
csvExportInProgress: boolean;
csvExportUrl: SafeUrl;
csvExportFileName: string;
- constructor(private sanitizer: DomSanitizer) {}
+ constructor(private sanitizer: DomSanitizer) {
+ this.renderedGroups = {};
+ }
+
+ ngOnInit() {
+ this.sortActions();
+ }
+
+ sortActions() {
+ const actions = this.gridContext.toolbarActions;
+
+ const unGrouped = actions.filter(a => !a.group)
+ .sort((a, b) => {
+ return a.label < b.label ? -1 : 1;
+ });
+
+ const grouped = actions.filter(a => Boolean(a.group))
+ .sort((a, b) => {
+ if (a.group === b.group) {
+ return a.label < b.label ? -1 : 1;
+ } else {
+ return a.group < b.group ? -1 : 1;
+ }
+ });
- ngOnInit() {}
+ // Insert group markers for rendering
+ const seen: any = {};
+ const grouped2: any[] = [];
+ grouped.forEach(action => {
+ if (!seen[action.group]) {
+ seen[action.group] = true;
+ const act = new GridToolbarAction();
+ act.label = action.group;
+ act.isGroup = true;
+ grouped2.push(act);
+ }
+ grouped2.push(action);
+ });
+
+ this.gridContext.toolbarActions = unGrouped.concat(grouped2);
+ console.log(this.gridContext.toolbarActions);
+ }
saveGridConfig() {
// TODO: when server-side settings are supported, this operation