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

Show filter options based on number of rows returned

2 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 27 May 2012, 12:57 AM
Hi there.

Could someone please give me a pointer as to how to display the column filters only if the number of rows INITIALLY returned by a grid is greater than x?

I say "initially" for a reason. Let's say x above is 20. If the grid initially returns 30 rows the filters will appear. But if I filter the grid so that only  5 rows come back based on my filter expression then the grid needs to know this is 5 out of 30 rows so it still needs to show the filters. I.e. It's the 30 that is important here, not the 5.

I'm assuming I will use the onDataBound event. But I dont know how to get the number of rows returned. And I assume there is a "total" variable I can tap into that is the number of rows regardless of any filter applied?

Thanks in advance.

Chris

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 May 2012, 06:45 AM
Hi,

I guess you need to check the total row count and assign filter. If total row count is less than 20, you need to disable filtering. After filtering if the count is 5 out of 30, still you need to show filtering.Try the following code snippet to achieve this functionality.

C#:
public static bool check=false;
 
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        check = true;
    }
    else
    {
        check = false;
    }
}
 
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (filtercount < 20 && check == false)
    {
        RadGrid1.AllowFilteringByColumn = false;
        RadGrid1.Rebind();
    }
}
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
{
    if (!check)
    {
        if (e.EventInfo is GridInitializePagerItem)
        {
            filtercount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;             
        }
    }   
 
}

Thanks,
Shinu.
0
Chris
Top achievements
Rank 1
answered on 28 May 2012, 07:09 AM
Thanks Shinu. That worked perfectly. :-)
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Share this question
or