I have a Grid which uses an IndexedContainer (although it’s populated from database content).
I’ve set up filters for columns via TextFields and Comboboxes in a HeaderRow.
Then I have a control somewhere else which, when clicked, changes completely the datasource of this Grid. It changes the query and refills the container.
The problem is that I’d want to keep the possible selected/inserted values for the column filters. There should be a way to simply reapply them after repopulating the datasource.
This approach has a series of problems/drawbacks. For instance, as I wanted to avoid the visual efect of completely emptying the Grid and suddenly refill it again, update its contents I compare each existing row with each row from the new query recordset and replace that contents in the Grid in case it has changed, thus obtaining a “smoother” content reloading effect.
But if I don’t remove the existing filters prior to this operation, the filtering gets “mad” soon, obtaining weird results starting from the next filtering operation.
I tried to save all existing filtering prior to that “refill” operation, as there is a DataSource.getContainerFilters method, in a list of filters, then remove them from the DataSource, repopulate the source itself, the reapply them again. But this doesn’t work as, as they are a reference, as soon as I do a DataSource.removeAllContainerFilters(), they will disappear from the list where I supposedly “saved” them “for later”.
Then I attempted the approach of refilling the filter controls with their same existing values in an attempt to reapply them again, as I read somewhere in the forum previously that programmatically setting a value for them would fire a ChangeValueEvent (which would have been my desirable 1st approach in case it also existed programmatically and/or I had known how to do it) – although I already had some evidence that this, in fact, wasn’t working.
So I tried it and, as I was wondering, getting the current value and setting it again for a TextField / ComboBox filter DOESN’T do anything, no matter if the field is set as immediate or if I do an explicit .commit() after changing its value.
In the end I’m doing a .setValue(“”) to at least visually remove the no-more existing (at DataSource level) filters.
Is there a way to explicitly re-apply the existing filters again or to make the Grid aware that the value has “changed” (although they really hold the same value) to get them effectively applied again?