代码之家  ›  专栏  ›  技术社区  ›  Bogdan

AG网格快速筛选更改以编程方式搜索的列

  •  0
  • Bogdan  · 技术社区  · 6 年前

    我需要一个快速搜索过滤器,用户可以在其中选择要搜索的列。我没有成功地实施这个行为。 我试过这个:

    this.columns.forEach(column=>{
                if (this.globalSearchSelectedColumns.indexOf(column.field)>-1) column.getQuickFilterText = (params)=> params.value.name;
                else column.getQuickFilterText = ()=> '';
            });
    this.grid.api.setColumnDefs(this.columns);
    this.grid.api.onFilterChanged();
    this.grid.api.resetQuickFilter();
    

    其中,this.columns是columns defs,this.grid是gridOptions,this.globalsearchselectedcolumns是要搜索的选定列,按column.field。

    3 回复  |  直到 6 年前
        1
  •  2
  •   nakhodkin Infinias    6 年前

    quickFilter getQuickFilterText columnDef

    1. gridColumnApi
    2. colDef

    disableFilterCol

      disableFilterCol = () => {
        var col = this.gridColumnApi.getColumn("athlete");
        var colDef = col.getColDef();
        colDef.getQuickFilterText = () => "";
        console.log("disable Athlete");
      };
    

    athlete

    live demo

    getQuickFilterText = () => ""

        2
  •  0
  •   Bogdan    6 年前

    this.grid.columnApi.getAllColumns().forEach(column=>{
        let def = column.getColDef();
        if (this.globalSearchSelectedColumns.indexOf(def.field)>-1) def.getQuickFilterText = undefined;
        else def.getQuickFilterText = ()=> '';
    });
    this.grid.api.onFilterChanged();
    

        3
  •  -1
  •   Pratik Bhat    6 年前


      let newColDef= [];
      this.columns.forEach(column=>{
                if (this.globalSearchSelectedColumns.indexOf(column.field)>-1)
                column.getQuickFilterText = (params)=> params.value.name;
                else column.getQuickFilterText = ()=> '';
    
                newColDef.push(column);
            });
    this.grid.api.setColumnDefs(newColDef);
    this.grid.api.onFilterChanged();
    this.grid.api.resetQuickFilter();
    this.grid.api.refreshHeader();   
    


    here

    github