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) {
24 // Extend selection up one row
25 this.context.selectMultiRowsPrevious();
27 this.context.selectPreviousRow();
29 evt.stopPropagation();
33 // Extend selection down one row
34 this.context.selectMultiRowsNext();
36 this.context.selectNextRow();
38 evt.stopPropagation();
42 this.context.toPrevPage()
43 .then(ok => this.context.selectFirstRow(), err => {});
44 evt.stopPropagation();
48 this.context.toNextPage()
49 .then(ok => this.context.selectFirstRow(), err => {});
50 evt.stopPropagation();
53 // control-a means select all visible rows.
54 // For consistency, select all rows in the current page only.
56 this.context.rowSelector.clear();
57 this.context.selectRowsInPage();
63 if (this.context.lastSelectedIndex) {
64 this.grid.onRowActivate.emit(
65 this.context.getRowByIndex(
66 this.context.lastSelectedIndex)
69 evt.stopPropagation();
74 onRowClick($event: any, row: any, idx: number) {
76 if (this.context.disableSelect) {
77 // Avoid any appearance or click behavior when row
78 // selection is disabled.
82 const index = this.context.getRowIndex(row);
84 if (this.context.disableMultiSelect) {
85 this.context.selectOneRow(index);
86 } else if ($event.ctrlKey || $event.metaKey /* mac command */) {
87 if (this.context.toggleSelectOneRow(index)) {
88 this.context.lastSelectedIndex = index;
91 } else if ($event.shiftKey) {
92 // TODO shift range click
95 this.context.selectOneRow(index);
98 this.grid.onRowClick.emit(row);
101 onRowDblClick(row: any) {
102 this.grid.onRowActivate.emit(row);