@Input() label: string;
@Input() action: (rows: any[]) => any;
+ // 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.
+ @Input() disabled: (rows: any[]) => boolean;
+
// get a reference to our container grid.
constructor(@Host() private grid: GridComponent) {}
action.label = this.label;
action.action = this.action;
+ action.disabled = (this.disabled == null) ? (rows: any[]) => false : this.disabled;
+
+
this.grid.context.toolbarActions.push(action);
}
}
-
class="material-icons mat-icon-in-button">playlist_add_check</span>
</button>
<div class="dropdown-menu" ngbDropdownMenu>
- <a class="dropdown-item" (click)="performAction(action)"
- *ngFor="let action of gridContext.toolbarActions">
+ <button class="dropdown-item" (click)="performAction(action)"
+ *ngFor="let action of gridContext.toolbarActions"
+ [disabled]="shouldDisableAction(action)">
<span class="ml-2">{{action.label}}</span>
- </a>
+ </button>
</div>
</div>
action.action(this.gridContext.getSelectedRows());
}
+ shouldDisableAction(action: GridToolbarAction) {
+ return action.disabled(this.gridContext.getSelectedRows());
+ }
+
printHtml() {
this.gridPrinter.printGrid();
}
export class GridToolbarAction {
label: string;
action: (rows: any[]) => any;
+ disabled: (rows: any[]) => boolean;
}
// Buttons are global actions
[rowFlairCallback]="btGridRowFlairCallback"
[cellClassCallback]="btGridCellClassCallback"
[sortable]="true">
+ <eg-grid-toolbar-action label="Action that needs a single row" i18n-label [action]="complimentEvergreen" [disabled]="notOneSelectedRow">
+ </eg-grid-toolbar-action>
<eg-grid-column name="test" [cellTemplate]="cellTmpl"
[cellContext]="btGridTestContext" [sortable]="false">
</eg-grid-column>
name = 'Jane';
+ complimentEvergreen: (rows: IdlObject[]) => void;
+ notOneSelectedRow: (rows: IdlObject[]) => boolean;
+
constructor(
private idl: IdlService,
private org: OrgService,
return cbt;
}));
};
+
+ this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!');
+ this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length != 1);
+
}
btGridRowClassCallback(row: any): string {