Filters are lost when doing a second query on a visualization


#1

Hi, I have an application in React Js and when I apply some filters and do a query it works fine, but when I do a second query, the filters that I applied are not in this new query.

I’m retrieving the data just like this:
image

Please tell me if I’m doing something wrong.


#2

Hi @emoya, Let me see if I understood correctly. I see in this method you are executing an already created query (otherwise you would not use cf.getVisualization()). This query dummy is affected at some point with filters. Then you execute the query again and the data being returned has doesn’t include the filters?

Can you try the following: When the filters are applied, please open the developer tools and run cf.getVisualization('dummy').get('config').filters and check if this is empty. In case it is, the query most have been overwritten at some point. Otherwise it should show the filters.

To go beyond, try running the entire code from the console:

cf.getVisualization('dummy')
.set('offset', 10)
.limit(100)
.execute().then(response => console.log(response.data))

If the data is filtered then the query in your getGridData is not the same (probably been overwritten somewhere else loosing the filters).


#3

Yes, you are understanding it the right way, I run the code in the console, and it only works the first time.

I think it is something like that the reference to my visualization is being lost and a new one is being created.

I try this: const myVizz = window.cf.getVisualization ('dummy') and it works fine, but very slowly.


#4

Should not be the case, as long as you create the visualization only once (the first time) , you can obtain the instance with the getVisualization() and call the .execute() as many as you want. It will always be the same instance and it will always return the promise that will give you the data after resolved.

On the issue related with the slowliness, I suggest to run a performance test because I don’t think is a CF issue. Maybe the component is being re-rendered too many times and unnecessarily executing the same query over and over. A performance benchmark will tell you what script and function is taking too long.


#5

Thanks for your answer Eduardo, you are right, I already solved it, I only had to create the instance once when mounting the component with useEffect:

useEffect(() => {
window.cf
.provider('provider')
.source('your_source')
.fields("field1", "field2", "field3", "field4")
.element("dummy")
.set("sort", [{"field":"desc"}]);
}, [])

Thank you very much for your help.