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

Custom and Regular Filtering Together

1 Answer 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Veteran
Jeff asked on 06 Nov 2012, 08:33 PM
I'm using a Radgrid with custom filtering. It all works fine. I also want to use the inherent filtering that comes with the Radgrid. I use the NeedDataSource when getting the results for my custom search logic and code. However, when the "regular" grid filtering is used, the results are okay, but the total items are based off my back end custom code which is wrong. Hope that made sense.

For example....

Custom Filtering - A datatable is obtained containing the results in the NeedDataSource(). The Grids VirtualItemCount is set to the Datatable.rows.count. So now I have a grid with lets say 25 total records ( 15 rows per page).

Non Custom Filtering - The user enters their search text via the Grids filtering textbox, clicks on the button. The NeedDataSource event is fired. The same original custom filtering is supplied to the backend. A datatable is returned just like before with the same results. And the Grids VirtualItemCount is again set to the total number of records like before. However, the Non Custom Filtering is applied ( I have no idea where..it's a mystery to me) and the correct results are displayed. For example purposes, lets say only three records are displayed based from what the user entered in the Grids filtering search textbox. But the total records are still being applied from the Datatable. So it's wrong.

I hope that made sense.  Bottom line, how in the world do you use both those types of filtering together?

1 Answer, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
Veteran
answered on 07 Nov 2012, 05:12 PM
Solved....

  • In ItemCommand event of the RadGrid, a flag is set.
  • In NeedDataSource of the RadGrid, the flag is evaluated. Depending on your logic either data is obtained from the custom filtering logic. Or data is retrieved comprising of the whole dataset and Grid applies the filtering.

bool bCustomFiltering  = true;

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if(e.CommandName == "Filter")
            bCustomFiltering = false;
}

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    if(bCustomFiltering == false)
     {
         get your data and do your custom filtering
     }
   else
     {
        get your complete set of data, and let the RadGrid do the filtering
     }
}
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Veteran
Answers by
Jeff
Top achievements
Rank 1
Veteran
Share this question
or