Hi,
We are using an igGrid with a comboBox to filter one column.We also have a searchBar outside igGrid to fetch and refreh the dataSource from a SQL query.We fetch the data in Ajax and then update the igGrid("option", "dataSource", data) in jquery
Here is the problem : after checking a few comboxBox, we noticed that changing the dataSource will reset the comboBox and keep only the last one.Here is a fiddle to test it, forked from your Excel-style Filtering fiddle : jsfiddle.net/.../
Step to reproduce : - Select 2 or 3 checkboxes from Category column
- click the refresh button at the bottom
The igGrid will refresh the dataSource but the combobox will unchek except the last one.
As you can see the dataSource.settings.filtering.expressions contains multiple objects for the same FieldName and i assume the igGridFiltering('filter') function look up only for the last object instead of adding them.I try to concatenate them into one object with multiple Expression but it doesnt works either.
Hello,
Thank you for your patience as we worked through the specifics of your use case. After reviewing your requirements and discussing potential solutions, I’ve come up with an approach that should address the described behavior while accommodating your very specific scenario.
The main challenge here is that both filtering through the UI and programmatic filtering (like after an AJAX refresh) trigger the same iggriddatabound event. Without extra logic to handle this, we can end up with redundant processing or even an infinite loop.
Your specific setup adds an extra layer of complexity because you’re frequently refreshing data via AJAX calls across multiple grids, and you want to avoid modifying every instance of dataBind.
To handle this, I’ve designed a solution that tracks the state of filters and uses flags and checks to decide when to apply or skip actions. The key is to distinguish between:
Here’s the core idea:
The described scenario could be observed here:
Sample Implementation
To make it even clearer, I’ve prepared a live example for you to review: Sample Code on JSFiddle
To handle this in your application, you have two paths:
While the first option is simpler and more scalable, the second can be more precise for grids with unique configurations.
I hope this explanation and sample help clarify the approach and how it addresses your specific scenario. Let me know if you have any questions or need further assistance with implementation.
Regards,
Georgi Anastasov
Associate Software Developer
Infragistics
Thank you for your response.Unfortunately, the bad news is that I have more than two hundred instances of .igGrid("dataBind") spread across my website, each triggered after every ajaxCall used to refresh my data.
.igGrid("dataBind")
ajaxCall
I can't apply the workaround update to every dataBind individually.
dataBind
I tried working with events like iggriddatabinding and iggriddatabound, but calling igGridFiltering() triggers a new data binding, and I end up in an infinite loop.
iggriddatabinding
iggriddatabound
igGridFiltering()
Do you think there's a way to factorize the solution?
Thank you for providing the detailed explanation and the fiddle to demonstrate the behavior. I noticed that when the igGrid’s dataSource is refreshed, the comboBox selections are not retained as expected.
To address this, I’ve created a solution that ensures all selected filter conditions persist, even after the grid refresh. Here’s what I’ve done:
Here’s the code I used:
// Retrieve the current filtering expressions from the igGrid's dataSource let currentFilters = $("#productsGrid").data("igGrid").dataSource.settings.filtering.expressions; // Initialize a map to combine filters with the same fieldName let combinedFiltersMap = {}; currentFilters.forEach(filter => { // Check if there is already a combined filter for this fieldName if (!combinedFiltersMap[filter.fieldName]) { // Initialize a new combined filter object for this fieldName combinedFiltersMap[filter.fieldName] = { fieldName: filter.fieldName, expr: [], // Array to store multiple filter expressions cond: filter.cond, logic: filter.logic || "OR" }; } // Add the current filter's expression to the combined filter's array combinedFiltersMap[filter.fieldName].expr.push(filter.expr); }); // Convert the map of combined filters into an array for use with the filtering method let combinedFilters = Object.values(combinedFiltersMap); // Apply the combined filters to the igGrid $("#productsGrid").igGridFiltering("filter", combinedFilters);
This approach works by consolidating all selected filter conditions for a specific column into a single filter object. The expr property of the filter object becomes an array containing all selected conditions, and the logic property determines how these conditions are combined (e.g., using "OR").
I’ve also created a working example that you can test here: Sample Link.
This approach should resolve the described behavior and allow the grid to retain all selected filters after refreshing. Please let me know if you have any questions or if there’s anything else I can assist you with.