Apply radgrid filter on multiple grids

3 posts, 1 answers
  1. Eva
    Eva avatar
    15 posts
    Member since:
    Mar 2017

    Posted 12 Jun 2017 Link to this post

    Hello,

    I have a page with a RadListView multiple RadGrids binded on server-side with the same type of objects and same columns.

    I would like to apply filters on all grids when changing a filter on one of them (client-side).

     

    I tried handling the following client events on each grid :

    - OnCommand, in order to save filters of the filtered grid in a global javascript variable

    - OnGridCreated, in order to apply saved filters on each grid using the javascript variable

     

    However, it doesn't work because my javascript variable is back to null value when hitting OnGridCreated event.

    Is there a better way to do this (= sharing filters between multiple grids) ?

     

    Thanks in advance.

    Best regards,

    Eva

  2. Eva
    Eva avatar
    15 posts
    Member since:
    Mar 2017

    Posted 12 Jun 2017 Link to this post

    Hello,

    I finally managed to retrieve the filters using the following code:

    function OnCommand(sender, eventArgs)
    {
        if (eventArgs.get_commandName() === "Filter") {
            window.grdFilters = sender.get_masterTableView().get_filterExpressions()._array.slice();
        }
    }
     
    function OnGridCreated(sender, eventArgs) {
        if (window.grdFilters && window.grdFilters != null) {
            var filters = window.grdFilters;
            var grd = sender.get_masterTableView();
            grd.get_filterExpressions().clear();
            for (var i = 0; i < filters.length; i++) {
                var filterExpression = filters[i];
                grd._updateFilterControlValue(filterExpression._fieldValue, filterExpression._columnUniqueName, filterExpression._filterFunction);
                grd._filterExpressions.add(filterExpression);
            }
        }
    }

     

    However, filters are not actually applied on other grids (although filter expressions have been set on the filterbox).

    How can I force the grids to apply those filters ?

    Thanks and regards.

  3. Answer
    Eyup
    Admin
    Eyup avatar
    4074 posts

    Posted 15 Jun 2017 Link to this post

    Hello Eva,

    Generally, for initiating a filter command from client-side, you should use the filter method:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/methods/filter

    Another approach is to initiate your custom fireCommand:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/methods/firecommand

    But this is not applicable in this scenario because it is not possible to call these postback-causing actions multiple times simultaneously. In order to achieve what you are looking after, you should use the OnItemCommand server-event handler of the filtered grid, similar to this:
    RadGrid gridFiltered = null;
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            gridFiltered = sender as RadGrid;
        }
    }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        otherGrid.MasterTableView.FilterExpression = gridFiltered.MasterTableView.FilterExpression;
        otherGrid.Rebind();
    }

    I hope this will prove helpful.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top