Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
Grid Filtering Events
posted

Hello,

I am developing a page that has a hierarchical grid on it; I have filtering turned on for all levels of this grid.

Separate from the grid control I am maintaining an array of filters to be applied at the various levels of the grid. These filtered fields are generally hidden columns on the grid. The data source is an MVC GridDataSourceAction that hooks up to an Entity driven IQueryable.

Currently I am using jquery event handlers to listen for the 'iggridrendered' and 'iggridfilteringdatafiltered' events, the event handler applies the filters I have constructed with my other custom controls. At this point I have to manually invoke filter() within the event handler so that the data will be filtered.

Example (filterHash is a hash set of the filters I am maintaining):

$this.on('iggridfilteringdatafiltered', function (evt, ui) {
    var $this = $(this),
         target = $(evt.target),
         data = target.data(),
         grid = data.igGrid,
         filterSettings = grid.dataSource.filterSettings();

   for (filterName in filterHash) {
      if (!filterSettings.expressions.contains(filterHash[filterName])) {
         filterSettings.expressions.add(filterHash[filterName]);
      }
   }

   target.igGridFiltering('filter', filterSettings.expressions, false);

});

These two events take care of applying the external filters when a child grid first appears and when the user manually enters a filtering criteria. The problem I have with this approach is that it requires two requests to the server, one with the user's initial filter and then one after I add the filters in filterHash.

If I use the 'iggridfilteringdatafiltering' I can correctly apply my filters and fire my own filter call (I cancel the original event afterwards). This works fine except that at the point when 'iggridfilteringdatafiltering' event is raised the "filterSettings().expressions" array has not been updated with the filter entered by the user.

If I add the filterHash filters to the expressions array and let the event continue it ignores those filters and only applies the ones visible in the Grid's filter bar.

The events 'iggriddatabinding' and 'iggriddatabound' are inadequate as well, before binding the expressions are not necessarily constructed and after binding the data has already been retrieved. 

My question is this: Is there an event or a function I can hook into after the expressions array has been constructed, but before the dataBind() call has been made? I want to manually manage the filters at this point of execution.