// DEPRECATED: Pass a reference to a function that is called on click.
@Input() action: () => any;
+ // Provide a router link instead of an onClick handler
+ @Input() routerLink: string;
@Input() set disabled(d: boolean) {
// Support asynchronous disabled values by appling directly
constructor(@Host() private grid: GridComponent) {
this.onClick = new EventEmitter<any>();
this.button = new GridToolbarButton();
- this.button.onClick = this.onClick;
}
ngOnInit() {
-
if (!this.grid) {
console.warn('GridToolbarButtonComponent needs a [grid]');
return;
}
+ this.button.onClick = this.onClick;
+ this.button.routerLink = this.routerLink;
this.button.label = this.label;
this.button.action = this.action;
this.grid.context.toolbarButtons.push(this.button);
import {Component, Input, OnInit} from '@angular/core';
+import {Router} from '@angular/router';
import {DomSanitizer, SafeUrl} from '@angular/platform-browser';
import {GridToolbarButton, GridToolbarAction, GridContext} from '@eg/share/grid/grid';
import {GridColumnWidthComponent} from './grid-column-width.component';
@Input() gridPrinter: GridPrintComponent;
@Input() disableSaveSettings = false;
- renderedGroups: {[group: string]: boolean};
+ renderedGroups: {[group: string]: boolean} = {};
csvExportInProgress: boolean;
csvExportUrl: SafeUrl;
csvExportFileName: string;
- constructor(private sanitizer: DomSanitizer) {
- this.renderedGroups = {};
- }
+ constructor(
+ private router: Router,
+ private sanitizer: DomSanitizer
+ ) {}
ngOnInit() {
this.sortActions();
performButtonAction(button: GridToolbarButton) {
const rows = this.gridContext.getSelectedRows();
- button.onClick.emit(rows);
- if (button.action) { button.action(); }
+ console.log('BUTTON ACTION', button.routerLink);
+ if (button.routerLink) {
+ this.router.navigate([button.routerLink]);
+ } else {
+ button.onClick.emit(rows);
+ if (button.action) { button.action(); }
+ }
}
printHtml() {