<!-- uses dropdown menu CSS for easy stying, but it's not a dropdown -->
<ng-template #contextMenu let-gridContext="gridContext">
- <ng-container *ngFor="let action of gridContext.toolbarActions">
- <ng-container *ngIf="action.separator">
- <div class="dropdown-divider"></div>
- </ng-container>
- <ng-container *ngIf="!action.separator">
- <a class="dropdown-item" (click)="performAction(action)">
- <span class="ml-2">{{action.label}}</span>
- </a>
- </ng-container>
- </ng-container>
+ <eg-grid-toolbar-actions-menu [gridContext]="gridContext">
+ </eg-grid-toolbar-actions-menu>
</ng-template>
<!--
if (this.context.disableMultiSelect) {
this.context.selectOneRow(index);
} else if ($event.ctrlKey || $event.metaKey /* mac command */) {
- if (this.context.toggleSelectOneRow(index)) {
- this.context.lastSelectedIndex = index;
- }
+ this.context.toggleSelectOneRow(index);
} else if ($event.shiftKey) {
// TODO shift range click
this.grid.onRowActivate.emit(row);
}
- performAction(action: GridToolbarAction) {
- action.action(this.context.getSelectedRows());
- }
-
// Apply row selection, track the new menu if needed,
// manually close any existing open menus, open selected menu.
onRowContextClick($event, row: any, contextMenu: NgbPopover) {
@Input() disableOnRows: (rows: any[]) => boolean;
// If true, render a separator bar only, no action link.
- @Input() separator: boolean;
+ @Input() isSeparator: boolean;
// get a reference to our container grid.
constructor(@Host() private grid: GridComponent) {
this.toolbarAction.group = this.group;
this.toolbarAction.action = this.action;
this.toolbarAction.disabled = this.disabled;
+ this.toolbarAction.isSeparator = this.isSeparator;
this.toolbarAction.disableOnRows = this.disableOnRows;
this.grid.context.toolbarActions.push(this.toolbarAction);
}
--- /dev/null
+<button class="dropdown-item scrollable-menu"
+ [disabled]="shouldDisable(action)"
+ (click)="performAction(action)"
+ *ngFor="let action of gridContext.toolbarActions">
+ <ng-container *ngIf="action.isGroup">
+ <span class="font-weight-bold font-italic">{{action.label}}</span>
+ </ng-container>
+ <ng-container *ngIf="action.isSeparator">
+ <div class="dropdown-divider"></div>
+ </ng-container>
+ <ng-container *ngIf="!action.isGroup && !action.isSeparator">
+ <!-- grouped entries are left paddded for group indentation -->
+ <span [ngClass]="{'ml-2': action.group}">{{action.label}}</span>
+ </ng-container>
+</button>
--- /dev/null
+import {Component, Input, OnInit, Host} from '@angular/core';
+import {GridToolbarAction, GridContext} from '@eg/share/grid/grid';
+
+/** Models a list of toolbar action menu entries */
+
+@Component({
+ selector: 'eg-grid-toolbar-actions-menu',
+ templateUrl: 'grid-toolbar-actions-menu.component.html'
+})
+
+export class GridToolbarActionsMenuComponent {
+
+ @Input() gridContext: GridContext;
+
+ performAction(action: GridToolbarAction) {
+ if (action.isGroup || action.isSeparator) {
+ return; // These don't perform actions
+ }
+ const rows = this.gridContext.getSelectedRows();
+ action.onClick.emit(rows);
+ if (action.action) { action.action(rows); }
+ }
+
+ shouldDisable(action: GridToolbarAction): boolean {
+ if (action.disableOnRows) {
+ return action.disableOnRows(this.gridContext.getSelectedRows());
+ }
+ return false;
+ }
+}
+
<span title="Actions For Selected Rows" i18n-title
class="material-icons mat-icon-in-button">playlist_add_check</span>
</button>
- <div class="dropdown-menu scrollable-menu" ngbDropdownMenu>
- <button class="dropdown-item" (click)="performAction(action)"
- *ngFor="let action of gridContext.toolbarActions"
- [disabled]="shouldDisableAction(action)">
- <ng-container *ngIf="action.isGroup">
- <span class="ml-2 font-weight-bold font-italic">{{action.label}}</span>
- </ng-container>
- <ng-container *ngIf="action.separator">
- <div class="dropdown-divider"></div>
- </ng-container>
- <ng-container
- *ngIf="!action.group && !action.isGroup && !action.separator">
- <span class="ml-2">{{action.label}}</span>
- </ng-container>
- </button>
+ <div class="dropdown-menu" ngbDropdownMenu>
+ <eg-grid-toolbar-actions-menu [gridContext]="gridContext">
+ </eg-grid-toolbar-actions-menu>
</div>
</div>
);
}
- performAction(action: GridToolbarAction) {
- if (action.isGroup || action.separator) {
- return; // These don't perform actions
- }
- const rows = this.gridContext.getSelectedRows();
- action.onClick.emit(rows);
- if (action.action) { action.action(rows); }
- }
-
performButtonAction(button: GridToolbarButton) {
const rows = this.gridContext.getSelectedRows();
button.onClick.emit();
if (button.action) { button.action(); }
}
- shouldDisableAction(action: GridToolbarAction) {
- if (action.disableOnRows) {
- return action.disableOnRows(this.gridContext.getSelectedRows());
- }
- return false;
- }
-
printHtml() {
this.gridPrinter.printGrid();
}
import {GridToolbarButtonComponent} from './grid-toolbar-button.component';
import {GridToolbarCheckboxComponent} from './grid-toolbar-checkbox.component';
import {GridToolbarActionComponent} from './grid-toolbar-action.component';
+import {GridToolbarActionsMenuComponent} from './grid-toolbar-actions-menu.component';
import {GridColumnConfigComponent} from './grid-column-config.component';
import {GridColumnWidthComponent} from './grid-column-width.component';
import {GridPrintComponent} from './grid-print.component';
GridToolbarButtonComponent,
GridToolbarCheckboxComponent,
GridToolbarActionComponent,
+ GridToolbarActionsMenuComponent,
GridColumnConfigComponent,
GridColumnWidthComponent,
GridPrintComponent
}
this.rowSelector.select(index);
+ this.lastSelectedIndex = index;
return true;
}
group: string;
disabled: boolean;
isGroup: boolean; // used for group placeholder entries
- separator: boolean;
+ isSeparator: boolean;
disableOnRows: (rows: any[]) => boolean;
}
<eg-grid-toolbar-action label="Action that needs a single row" i18n-label
[action]="complimentEvergreen" [disableOnRows]="notOneSelectedRow">
</eg-grid-toolbar-action>
+ <eg-grid-toolbar-action [isSeparator]="true">
+ </eg-grid-toolbar-action>
+ <eg-grid-toolbar-action label="Another Action" i18n-label
+ (actionClick)="complimentEvergreen2($event)">
+ </eg-grid-toolbar-action>
<eg-grid-column name="test" [cellTemplate]="cellTmpl"
[cellContext]="btGridTestContext" [sortable]="false">
</eg-grid-column>
this.sbChannel.postMessage({msg : $event.target.value});
}
+ // Example of click handler for row action
+ complimentEvergreen2(rows: IdlObject[]) {
+ alert('I know, right?');
+ }
+
openEditor() {
this.fmRecordEditor.open({size: 'lg'}).then(
ok => { console.debug(ok); },