【问题标题】:Typeahead with ag-grid using Angular 2使用 Angular 2 使用 ag-grid 提前输入
【发布时间】:2017-04-13 11:25:47
【问题描述】:

我使用自定义过滤器制作了一个带有 ag-grid 的表格。我想在搜索字段中添加预输入/自动完成功能。但我收到一个错误:

无法绑定到“ngbTypeahead”,因为它不是“输入”的已知属性。 (" 过滤器:][ngbTypeahead]="搜索" (ngModelChange)="onChange($event)" [ngModel]="文本"> "): ProjectFilterComponent@2:8

我在自定义过滤器中使用外部库 (ng-bootstrap) 进行预输入。

@Component({
selector: 'filter-cell',
template: `
    Filter: <input style="height: 20px"
    [ngbTypeahead]="search"
    (ngModelChange)="onChange($event)"
    [ngModel]="text">
`

})

class ProjectFilterComponent implements AgFilterComponent{
public params:IFilterParams;
public valueGetter:(rowNode:RowNode) => any;
public text;
allTextFromProject = this.order.projects

constructor(private order : WorkorderComponent){


}

@ViewChild('projectinput', {read: ViewContainerRef}) public input;




agInit(params:IFilterParams):void {
    this.params = params;
    this.valueGetter = params.valueGetter;


}

isFilterActive():boolean {
    return this.text !== null && this.text !== undefined && this.text !== '';
}

doesFilterPass(params:IDoesFilterPassParams):boolean {
    return this.text.toLowerCase()
        .split(" ")
        .every((filterWord) => {
            return this.valueGetter(params.node).toString().toLowerCase().indexOf(filterWord) >= 0;
        });
}

getModel():any {
    return {value: this.text};
}

setModel(model:any):void {
    this.text = model.value;
}

afterGuiAttached(params:IAfterFilterGuiAttachedParams):void {

    this.input.element.nativeElement.focus();
}

search = (text$: Observable<string>) =>{
    text$
        .debounceTime(200)
        .distinctUntilChanged()
        .map(term => term.length < 1 ? []
            : this.order.projects.filter(v => new RegExp(term, 'gi').test(v)).splice(0, 10));


onChange(newValue):void {
    if (this.text !== newValue) {
        console.log(newValue)

        this.text = newValue;
        this.order.filterFunction(newValue, this.params.colDef.colId, this.order.page)



    }
}

[ngbTypeahead] 在其他不使用 ag-grid 的搜索字段中运行良好。我需要 ag-grid 的搜索字段中的 [ngbTypeahead] 函数

【问题讨论】:

    标签: angular autocomplete typeahead ag-grid ng-bootstrap


    【解决方案1】:

    在您的 createColomnDefs() 方法中将 NgbTypeaheadModuleNgbModule 导入到您的 ModuleImports 中,如下所示:

    createColumnDefs()  {
        this.columnDefs =[
            { headerName: "Extern id", field: "externalRefId", width:150, colId:"workorder.externalRefId",
                filterFramework:{
                component: PartialMatchFilterComponent,
                moduleImports: [FormsModule, NgbModule, NgbTypeaheadModule ]
            }},
    

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 2018-10-26
      • 2020-03-07
      • 1970-01-01
      • 2019-08-15
      • 1970-01-01
      • 2017-12-03
      • 2017-04-04
      • 2017-04-29
      相关资源
      最近更新 更多