1 import {Component, Input, OnInit, Host} from '@angular/core';
2 import {GridContext, GridColumn, GridRowSelector,
3 GridColumnSet, GridDataSource} from './grid';
4 import {GridComponent} from './grid.component';
7 selector: 'eg-grid-body',
8 templateUrl: './grid-body.component.html'
11 export class GridBodyComponent implements OnInit {
13 @Input() context: GridContext;
15 constructor(@Host() private grid: GridComponent) {}
19 // Not using @HostListener because it only works globally.
20 onGridKeyDown(evt: KeyboardEvent) {
23 this.context.selectPreviousRow();
24 evt.stopPropagation();
27 this.context.selectNextRow();
28 evt.stopPropagation();
31 this.context.toPrevPage()
32 .then(ok => this.context.selectFirstRow(), err => {});
33 evt.stopPropagation();
36 this.context.toNextPage()
37 .then(ok => this.context.selectFirstRow(), err => {});
38 evt.stopPropagation();
41 if (this.context.lastSelectedIndex) {
42 this.grid.onRowActivate.emit(
43 this.context.getRowByIndex(
44 this.context.lastSelectedIndex)
47 evt.stopPropagation();
52 onRowClick($event: any, row: any, idx: number) {
53 const index = this.context.getRowIndex(row);
55 if (this.context.disableMultiSelect) {
56 this.context.selectOneRow(index);
57 } else if ($event.ctrlKey || $event.metaKey /* mac command */) {
58 if (this.context.toggleSelectOneRow(index)) {
59 this.context.lastSelectedIndex = index;
62 } else if ($event.shiftKey) {
63 // TODO shift range click
66 this.context.selectOneRow(index);
69 this.grid.onRowClick.emit(row);
72 onRowDblClick(row: any) {
73 this.grid.onRowActivate.emit(row);