Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ag网格中的自定义过滤器在Angular 10应用程序中不起作用_Angular_Ag Grid_Ag Grid Angular - Fatal编程技术网

ag网格中的自定义过滤器在Angular 10应用程序中不起作用

ag网格中的自定义过滤器在Angular 10应用程序中不起作用,angular,ag-grid,ag-grid-angular,Angular,Ag Grid,Ag Grid Angular,我正在开发一个使用ag网格的演示应用程序。我需要创建一个自定义过滤器,用于使用ranger过滤数字。所以我为它创建了一个自定义过滤器。但过滤器不工作,并显示在网格的头部部分。代码如下: 应用程序组件html: <ag-grid-angular #agGrid style="width: 100%; height: 500px;" domLayout='normal' class="ag-theme-alpine" [rowDa

我正在开发一个使用ag网格的演示应用程序。我需要创建一个自定义过滤器,用于使用ranger过滤数字。所以我为它创建了一个自定义过滤器。但过滤器不工作,并显示在网格的头部部分。代码如下:

应用程序组件html:

<ag-grid-angular 
  #agGrid
  style="width: 100%; height: 500px;"
  domLayout='normal'
  class="ag-theme-alpine" 
  [rowData]="rowData" 
  [defaultColDef]="defaultColDef"
  [columnDefs]="columnDefs"
  [statusBar]="statusBar"
  rowSelection="multiple"
  (gridReady)="onGridReady($event)"
  floatingFilter="true"
  [singleClickEdit]="true"
  >
</ag-grid-angular>
import { MemberInfoService } from './_Services/member-info.service';
import { Component, OnInit } from '@angular/core';
import { ColDef, GridApi } from 'ag-grid-community';
import 'ag-grid-enterprise';
import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
import { SliderFloatingFilter } from './SliderFloatingFilter/slider-floating-filter.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'Ng-Grid Example';

  private gridApi: GridApi;
  private gridColumnApi;
  public statusBar;

  rowData: any;
  columnDefs: ColDef[] = null;
  frameworkComponents;

  constructor(private memberService: MemberInfoService) { }

  defaultColDef: {
    editable: false,
    sortable: true,
    filter: 'agTextColumnFilter'
  }

  ngOnInit(): void {
    this.columnDefs = [
      {
        headerName: 'Member Id', field: 'MemberId', sortable: true, filter: 'agNumberColumnFilter',
        width: 150,
        checkboxSelection: true, headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true 
      },
      { headerName: 'Member Name', field: 'MemberName', sortable: true, filter: 'agTextColumnFilter' },
      { headerName: 'Category', field: 'Category', sortable: true, filter: 'agTextColumnFilter', width: 150 },
      { headerName: 'Floor', field: 'Floor', sortable: true, filter: 'agTextColumnFilter' },
      { headerName: 'Shop No', field: 'ShopNo', sortable: true, filter: 'agTextColumnFilter', width: 150 },
      { headerName: 'Shop Name', field: 'ShopName', sortable: true, filter: 'agTextColumnFilter' },
      {
        headerName: 'Amount', field: 'Amount', editable: true, sortable: false, filter: 'agNumberColumnFilter',
        valueParser: ({ newValue, oldValue }) => isNaN(Number(newValue)) ? oldValue : Number(newValue),
        pinned: 'right', width: 150,
        //cellStyle: { color: '#fff', 'background-color': '#37474f' },        
        // cellStyle: ({ value }) => ({
        //   'background-color': value > 1000 ? 'green' : 'white'
        // }),
        cellClassRules: {
          'cell-value-negative': ({ value }) => value < 0,
          'cell-value-positive': ({ value }) => value >= 0
        },
        floatingFilterComponent: 'sliderFloatingFilter',
        floatingFilterComponentParams: {
          maxValue: 0,
          suppressFilterButton: true,
        },
        suppressMenu: false,
      }
    ];

    this.statusBar = {
      statusPanels: [
        {
          statusPanel: 'agTotalAndFilteredRowCountComponent',
          align: 'left',
        },
        {
          statusPanel: 'agTotalRowCountComponent',
          align: 'center',
        },
        { statusPanel: 'agFilteredRowCountComponent' },
        { statusPanel: 'agSelectedRowCountComponent' },
        { statusPanel: 'agAggregationComponent' },
      ],
    };

    this.rowData = this.memberService.getMemberInfo();

    this.frameworkComponents = { sliderFloatingFilter: SliderFloatingFilter };
  }

  // onGridReady({ api }: { api: GridApi }) {    
  //   this.gridApi = api;    
  //   this.gridApi.sizeColumnsToFit();
  // }

  onGridReady(params) {
    this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    params.api.sizeColumnsToFit();
    window.addEventListener('resize', function () {
      setTimeout(function () {
        params.api.sizeColumnsToFit();
      });
    });

    params.api.sizeColumnsToFit();
  }
}
<input 
    type="range" 
    min="0" 
    [max]="maxValue" 
    data-show-value="true" 
    data-popup-enabled="true" 
    [(ngModel)]="currentValue"
    (ngModelChange)="valueChanged()" />
import { Component } from '@angular/core';
import { AgFrameworkComponent } from 'ag-grid-angular';
import {IFloatingFilter,IFloatingFilterParams,NumberFilter,NumberFilterModel,} from 'ag-grid-community';

export interface SliderFloatingFilterParams extends IFloatingFilterParams {
  value: number;
  maxValue: number;
}

@Component({
  templateUrl: './slider-floating-filter.component.html'
})
export class SliderFloatingFilter implements IFloatingFilter, AgFrameworkComponent<SliderFloatingFilterParams> {
  public params: SliderFloatingFilterParams;

  public maxValue: number;
  public currentValue: number;

  agInit(params: SliderFloatingFilterParams): void {
    this.params = params;
    this.maxValue = this.params.maxValue;
    this.currentValue = 0;
  }

  valueChanged() {
    let valueToUse = this.currentValue === 0 ? null : this.currentValue;
    this.params.parentFilterInstance(function (instance) {
      (<NumberFilter>instance).onFloatingFilterChanged(
        'greaterThan',
        valueToUse
      );
    });
  }

  onParentModelChanged(parentModel: NumberFilterModel): void {
    if (!parentModel) {
      this.currentValue = 0;
    } 
    else {      
      this.currentValue = parentModel.filter;
    }
  }
}

您需要将
框架组件
传递到网格实例,将html代码更改为:

<ag-grid-angular 
  #agGrid
  style="width: 100%; height: 500px;"
  domLayout='normal'
  class="ag-theme-alpine" 
  [rowData]="rowData" 
  [defaultColDef]="defaultColDef"
  [columnDefs]="columnDefs"
  [statusBar]="statusBar"
  rowSelection="multiple"
  [frameworkComponents]="frameworkComponents"
  (gridReady)="onGridReady($event)"
  [singleClickEdit]="true"
  >
</ag-grid-angular>

.

谢谢,它正在工作。但另一个问题被发现了。我无法滑动到过滤器。在您的演示中,它不起作用。如果您总是在自定义过滤器组件中将
maxValue
设置为0,请更改该值。max值是用this.params.maxValue设置的;如何更改参数值更改传入的值,在
AppComponent
中,更改
floatingfiltercomponentpams
中的
maxValue
,听起来像是一个不同的问题,您应该提出一个新问题。
entryComponents: [SliderFloatingFilterComponent]