'How do you add a JSON filter before fetching data for ag-grid?
I am trying to pull data from a JSON file into an AG-Grid. I am able to pull all of the data into the table, but I want to apply a filter before the data gets into the table. I want to be able to use one of the fields to determine if that row should be added to the AG-Grid table.
Currently using this for all data:
fetch('https://raw.githubusercontent.com/tjbreshears/VBelo/main/outputs/teams.json')
.then(response => response.json())
.then(data => {
gridOptions.api.setRowData(data);
});
I want to add something like:
jsonObject.filter(obj=> obj.eligible == "1");
Solution 1:[1]
You could apply the filter to the data, thereby creating a new array, and then use that filtered array to set the data in the grid.
fetch('https://raw.githubusercontent.com/tjbreshears/VBelo/main/outputs/teams.json')
.then(response => response.json())
.then(data => {
filteredData = data.filter(obj=> obj.eligible == "1");
gridOptions.api.setRowData(filteredData);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alan Richardson |
