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

Hide filters depending on item count

3 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 21 Feb 2011, 02:38 PM
Is it possible to hide the filter controls depending on the item count of the RadGrid, or if the pager is shown?

Ideally I don't want to show the filter boxes if the results already fit on one page, has anyone done this before?

Cheers

Jon

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Feb 2011, 05:40 AM
Hello Jon,
Give a try with the following code to achieve your scenario.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (RadGrid1.PageCount ==1 && e.Item is GridFilteringItem )
        {
                GridFilteringItem gfItem = (GridFilteringItem)e.Item;
                gfItem.Visible = false;
        }
    }

Thanks,
Shinu.
0
Jonathan
Top achievements
Rank 1
answered on 23 Feb 2011, 01:54 PM
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
{
    if (e.EventInfo is GridInitializePagerItem)
    {
        int allRowsCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
        if ((allRowsCount < 11) && RadGrid1.MasterTableView.FilterExpression=="")
            RadGrid1.AllowFilteringByColumn = false;
    }
}

Was the code that got me the best result in the end.

Cheers

Jon
0
Jonathan
Top achievements
Rank 1
answered on 23 Feb 2011, 02:01 PM
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) 
    if (e.EventInfo is GridInitializePagerItem) 
    
        int allRowsCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; 
        if ((allRowsCount <= RadGrid1.PageSize) && RadGrid1.MasterTableView.FilterExpression=="") 
            RadGrid1.AllowFilteringByColumn = false; 
    
}

Or like this so it always matches the pager.
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jonathan
Top achievements
Rank 1
Share this question
or