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

Add custom filter option under Default filter, but expression will not combine to other filter's expression

0 Answers 63 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Li
Top achievements
Rank 1
Li asked on 24 Jul 2017, 08:52 PM

Hi,

I am trying to add a custom filter option under default filter, in my grid there are two columns will use default filter, and others will be under FilterTemplate

1. newly added custom filter option called "Large Losses" will be added to both of columns filter. I donot want. (I used js to invisible the one). 

2. my Large Losses custom option is working with expression. but the issue is that after my Large Losses option is applied to the grid, I apply another filter option to the grid from another column, the Large Losses filter is gone, only the one applied after it shown in the grid. The other way around, If I apply other filter option first, then apply my Large Losses on top of it, it works fine, both filter result under AND shown in the grid.

3. Please help, while I debugging the code, found that my Large Losses expression is not kept when I apply another filter on top of it.

 

aspx:

<telerik:GridNumericColumn UniqueName="totalincurred" HeaderText="Incurred" DataField="totalincurred" Aggregate="Sum"  
                        AllowFiltering="true" DataType="System.Decimal" FilterControlWidth="80px" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"   FooterStyle-HorizontalAlign="Right" DataFormatString="{0:N}">
 </telerik:GridNumericColumn>

 

C#:

   protected void LossesGrid_Init(object sender, EventArgs e)
        {
            GridFilterMenu filterMenu = LossesGrid.FilterMenu;
            RadMenuItem menuItem = new RadMenuItem();
            menuItem.Text = "Large Losses";
            menuItem.Value = "LargeLosses";
            LossesGrid.FilterMenu.Items.Add(menuItem);

            filterMenu.ItemClick += new RadMenuEventHandler(filterMenu_ItemClick);

}

   protected void filterMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            GridFilteringItem filterItem = LossesGrid.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
            filterItem.FireCommandEvent("Filter", new Pair(e.Item.Value, e.Item.Attributes["totalincurred"]));
        }

 

 protected void LossesGrid_ItemCommand(object sender, GridCommandEventArgs e)
 {

 if (e.CommandName == RadGrid.FilterCommandName)
            {
                AOId = (this.Master as Main).AccountOverviewId;
                VersionNo = (this.Master as Main).VersionNumber();
           
                Pair filterPair = (Pair)e.CommandArgument;
             
                if (filterPair.First.ToString() == "LargeLosses")
                {
                    e.Canceled = true;
                    string newFilter = "(totalincurred >= 25000)";

                    if (LossesGrid.MasterTableView.FilterExpression == "")
                    {
                        LossesGrid.MasterTableView.FilterExpression = newFilter;
                    }
                    else
                    {
                        LossesGrid.MasterTableView.FilterExpression = "((" + LossesGrid.MasterTableView.FilterExpression + ") AND (" + newFilter + "))";
                    }
              
                   LossesGrid.Rebind();
                }
            }         

}

No answers yet. Maybe you can help?

Tags
Filter
Asked by
Li
Top achievements
Rank 1
Share this question
or