Blame view

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