}
// Entry ID of the default entry to select (optional)
- // onChange() is NOT fired when applying the default value
+ // onChange() is NOT fired when applying the default value,
+ // unless startIdFiresOnChange is set to true.
@Input() startId: any;
+ @Input() startIdFiresOnChange: boolean;
@Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;
const entry =
this.entrylist.filter(e => e.id === this.startId)[0];
+
if (entry) {
this.selected = entry;
this.defaultSelectionApplied = true;
+ if (this.startIdFiresOnChange) {
+ this.selectorChanged(
+ {item: this.selected, preventDefault: () => true});
+ }
}
}
}
--- /dev/null
+import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
+import {GridToolbarCheckbox} from './grid';
+import {GridComponent} from './grid.component';
+
+@Component({
+ selector: 'eg-grid-toolbar-checkbox',
+ template: '<ng-template></ng-template>'
+})
+
+export class GridToolbarCheckboxComponent implements OnInit {
+
+ // Note most input fields should match class fields for GridColumn
+ @Input() label: string;
+
+ // This is an input instead of an Output because the handler is
+ // passed off to the grid context for maintenance -- events
+ // are not fired directly from this component.
+ @Input() onChange: (checked: boolean) => void;
+
+ // get a reference to our container grid.
+ constructor(@Host() private grid: GridComponent) {}
+
+ ngOnInit() {
+
+ if (!this.grid) {
+ console.warn('GridToolbarCheckboxComponent needs a [grid]');
+ return;
+ }
+
+ const cb = new GridToolbarCheckbox();
+ cb.label = this.label;
+ cb.onChange = this.onChange;
+
+ this.grid.context.toolbarCheckboxes.push(cb);
+ }
+}
+
<div class="eg-grid-toolbar mb-2">
- <div class="btn-toolbar" *ngIf="gridContext.toolbarButtons.length">
- <div class="btn-grp">
+ <div class="btn-toolbar">
+
+ <!-- buttons -->
+ <div class="btn-grp" *ngIf="gridContext.toolbarButtons.length">
<button *ngFor="let btn of gridContext.toolbarButtons"
class="btn btn-outline-dark" (click)="btn.action()">
{{btn.label}}
</button>
</div>
+
+ <!-- checkboxes -->
+ <div class="form-check form-check-inline"
+ *ngIf="gridContext.toolbarCheckboxes.length">
+ <ng-container *ngFor="let cb of gridContext.toolbarCheckboxes">
+ <label class="form-check-label">
+ <input class="form-check-input" type="checkbox"
+ (click)="cb.onChange($event.target.checked)"/>
+ {{cb.label}}
+ </label>
+ </ng-container>
+ </div>
</div>
<!-- push everything else to the right -->
font-size: 20px;
}
+.eg-grid-toolbar .form-check-label:nth-child(even) {
+ padding-left: 5px;
+ padding-right: 5px;
+ margin-left: 3px;
+ margin-right: 3px;
+ border-radius: 5px;
+ background-color: rgba(0,0,0,.03);
+ border: 1px solid rgba(0,0,0,.125);
+}
+
/* Kind of hacky -- only way to get a toolbar button with no
* mat icon to line up horizontally with mat icon buttons */
.eg-grid-toolbar .text-button {
import {GridBodyCellComponent} from './grid-body-cell.component';
import {GridToolbarComponent} from './grid-toolbar.component';
import {GridToolbarButtonComponent} from './grid-toolbar-button.component';
+import {GridToolbarCheckboxComponent} from './grid-toolbar-checkbox.component';
import {GridToolbarActionComponent} from './grid-toolbar-action.component';
import {GridColumnConfigComponent} from './grid-column-config.component';
import {GridColumnWidthComponent} from './grid-column-width.component';
GridBodyCellComponent,
GridToolbarComponent,
GridToolbarButtonComponent,
+ GridToolbarCheckboxComponent,
GridToolbarActionComponent,
GridColumnConfigComponent,
GridColumnWidthComponent,
GridComponent,
GridColumnComponent,
GridToolbarButtonComponent,
+ GridToolbarCheckboxComponent,
GridToolbarActionComponent
],
providers: [
columnSet: GridColumnSet;
rowSelector: GridRowSelector;
toolbarButtons: GridToolbarButton[];
+ toolbarCheckboxes: GridToolbarCheckbox[];
toolbarActions: GridToolbarAction[];
lastSelectedIndex: any;
pageChanges: Subscription;
this.pager.limit = 10;
this.rowSelector = new GridRowSelector();
this.toolbarButtons = [];
+ this.toolbarCheckboxes = [];
this.toolbarActions = [];
}
action: () => any;
}
+export class GridToolbarCheckbox {
+ label: string;
+ onChange: (checked: boolean) => void;
+}
+
export class GridDataSource {
data: any[];