editor.component.ts 1.21 KB
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;
    }
}