admin管理员组

文章数量:1125573

I am using ag-grid-community 33.0.3 and ag-grid-angular 33.0.3

I have code that sets column filter using the api


  applyNumberFilter(operation: OperationsFormValue) {
    const filterModel = this.params.api.getFilterModel();

    const gridFilter: NumberFilterModel = {
      filterType: "number",
      type: operation.operator,
      filter: operation.value1,
      filterTo: operation.value2,
    };
    filterModel[this.colId] = gridFilter;
    console.log("Set", filterModel);
    this.params.api.setFilterModel({ ...filterModel });
    console.log("Get", this.params.api.getFilterModel());
  }

the output in the console looks like this

Set {"time_duration":{"filterType":"number","type":"equals","filter":55,"filterTo":null}}
Get {"time_duration":{"filterType":"text","type":"equals","filter":"55"}}

Any ideas why it is being changed to text filter

In my defaultColDef i have

cellDataType: false

I am using ag-grid-community 33.0.3 and ag-grid-angular 33.0.3

I have code that sets column filter using the api


  applyNumberFilter(operation: OperationsFormValue) {
    const filterModel = this.params.api.getFilterModel();

    const gridFilter: NumberFilterModel = {
      filterType: "number",
      type: operation.operator,
      filter: operation.value1,
      filterTo: operation.value2,
    };
    filterModel[this.colId] = gridFilter;
    console.log("Set", filterModel);
    this.params.api.setFilterModel({ ...filterModel });
    console.log("Get", this.params.api.getFilterModel());
  }

the output in the console looks like this

Set {"time_duration":{"filterType":"number","type":"equals","filter":55,"filterTo":null}}
Get {"time_duration":{"filterType":"text","type":"equals","filter":"55"}}

Any ideas why it is being changed to text filter

In my defaultColDef i have

cellDataType: false
Share Improve this question asked 2 days ago DaleDale 4103 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If the column you are applying the number filter to does not have cellDataType set, then AG Grid does not know the type of data in that column -- cellDataType=false in your defaultColDef stops AG Grid from inferring the data types in all columns. AG Grid defaults the filter type to text if it doesn't know the data type of the column it's being applied to.

Confirmed here https://codesandbox.io/p/sandbox/d7pkv4. Then click the "Set Custom Filter" button to see the filter model printed to the console for the "age" column. You'll see it prints with filterType: "text" even though I defined filterType: "number." Then either add cellDataType: "number" to the age column definition or remove cellDataType: false from the defaultColDef. You'll see the printed filter model has filterType: "number" as defined.

本文标签: ag gridSetting AGGrid number filter saves it as a text filterStack Overflow