This is a migrated thread and some comments may be shown as answers.

Apply radgrid filter on multiple grids

2 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eva
Top achievements
Rank 1
Eva asked on 12 Jun 2017, 09:39 AM

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 Answers, 1 is accepted

Sort by
0
Eva
Top achievements
Rank 1
answered on 12 Jun 2017, 10:22 AM

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.

0
Accepted
Eyup
Telerik team
answered on 15 Jun 2017, 08:53 AM
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.
Tags
Grid
Asked by
Eva
Top achievements
Rank 1
Answers by
Eva
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or