【问题标题】:How to reduce the filter options from the defaultColDef in ag-grid?如何从 ag-grid 中的 defaultColDef 减少过滤器选项?
【发布时间】:2021-05-18 22:34:14
【问题描述】:

我正在尝试将 AG-Grid 合并到我的 Angular 应用程序中。我正在使用 defaultColDef,它提供了很多过滤器选项,即:包含、不包含、开始于、结束于、等于和不等于。我只需要三个开头,等于和包含。

<div *ngIf="tableOption">
  <ag-grid-angular class="ag-theme-alpine" id="ag-grid" 
    [pagination]="true" 
    paginationPageSize=10 
    [rowData]="rowData" 
    domLayout='autoHeight' 
    [columnDefs]="ColumnHeader" 
    [defaultColDef]="defaultColDef" 
    [enableRangeSelection]="true" 
    [rowSelection]="rowSelection" 
    [rowGroupPanelShow]="rowGroupPanelShow" 
    [pivotPanelShow]="pivotPanelShow">
  </ag-grid-angular>
</div>

我尝试在我的组件中设置过滤器选项,但它没有生效。

 public columnTitles = [{
     field: 'importance',
     maxWidth: 120,
     valueGetter: 'node.Importance',
     cellRenderer: 'loadingCellRenderer',
     sortable: true,
     suppressMenu: true,
     filter: 'ImportanceFilter',
     filterParams: {
       filterOptions: ['equals', 'contains', 'startsWith']
     }
   }
   //,...
 ];

 constructor(
   private route: ActivatedRoute,
   private singleUrlService: SingleUrlService,
   private formBuilder: FormBuilder) {
   this.defaultColDef = {
     enableRowGroup: true,
     enablePivot: true,
     enableValue: true,
     sortable: true,
     resizable: true,
     flex: 1,
     minWidth: 150,
     filter: true,
     enableRangeSelection: true,
     pagination: true,
     filterOptions: ['equals', 'contains', 'startWith']
   };
 }

【问题讨论】:

    标签: angular ag-grid


    【解决方案1】:

    您在defaultColDef 对象上设置filterOptions,而您需要在defaultColDef 上设置filterParams。请尝试以下操作:

    this.defaultColDef = {
      enableRowGroup: true,
      enablePivot: true,
      enableValue: true,
      sortable: true,
      resizable: true,
      flex: 1,
      minWidth: 150,
      filter: true,
      enableRangeSelection: true,
      pagination: true,
      filterParams: {
          filterOptions: ['equals', 'contains', 'startWith']
        }
    };
    

    【讨论】:

    • 嗨@SprintIsLove,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
    猜你喜欢
    • 2016-09-26
    • 2018-02-06
    • 2017-10-17
    • 2019-08-30
    • 2022-10-13
    • 1970-01-01
    • 2018-03-15
    • 2020-06-12
    • 2019-07-28
    相关资源
    最近更新 更多