Blame view

src/app/components/editor.component.ts 1.21 KB
abf7c25f   Yarik   Dropdown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  import { Component, ViewContainerRef, ViewChild, AfterViewInit } from '@angular/core';
  
  import { AgEditorComponent } from 'ag-grid-ng2/main';
  
  import { RegionSelectList } from '../models/regionselectlist';
  
  @Component({
      selector: 'editor-cell',
      template: `
          <div #container>
              <p *ngFor="let item of data" (click)="onClick(item)" >{{item.name}}</p>
          </div>
      `
  })
  export class EditorComponent implements AgEditorComponent, AfterViewInit {
      @ViewChild('container', {read: ViewContainerRef}) public container;
      public item: any;
      public data: RegionSelectList[];
      private params: any;
      ngAfterViewInit() {
          this.container.element.nativeElement.focus();
      }
  
      agInit(params: any): void {
          this.params = params;
          this.data = params.data || [];
          // this.setHappy(params.value === "Happy");
      }
  
      getValue(): any {
          return this.item;
      }
  
      isPopup(): boolean {
          return true;
      }
  
      setValue(item: any): void {
          this.item = item;
      }
  
      onClick(item: any) {
          this.setValue(item);
          this.params.api.stopEditing();
      }
  
      onKeyDown(event): boolean {
          event.stopPropagation();
          return false;
      }
  }