ag-grid external filter for columns that doesn't exists in the grid (server side model)

Viewed 145

Using ag-grid with react.

I have seen the external filtering and worked it out with server side filtering.

But the external filtering is working with columns which exists in the grid, I want to be able to have an external filter for a field that does not exists in the grid.

For example:

My grid has columns: col1, col2, col3

And I want to have an external filter for free text search or col4.

I have made this work with what feels like a hack to me, by adding an hidden column to the grid and updating it with gridApi.setFilterModel(myFilter) on external filter change.

Tried with react state:

function createServerSideDatasource(getData: any) {
return {
  getRows: async function (params: any) {
    const response = await getData(params.request);
    if (response.success) {
      params.success({
        rowData: response.rows,
        rowCount: response.rowCount,
      });
    } else {
      params.fail();
    }
  },
};
}

const onGridReady = (params: GridReadyEvent) => {
    const dataSource = createServerSideDatasource(getData);
    params.api.setServerSideDatasource(dataSource);
};

function getData(request: any){
    //here i don't have access to my component state, only to the initial values
}
0 Answers
Related