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

Clearing filter with customfiltering column

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nilanjan
Top achievements
Rank 1
Nilanjan asked on 31 Mar 2009, 09:42 AM
I have a radgrid where there is a column that needs to be filtered with drop down list.

I am setting up a dummy grid with data to explain my requirement.

ColumnA    ColumnB    ColumnC
------------  -------------  -------------
     a                b                c
     a                e                f
     g                h                i

Suppose, column A and B are filtered with default text box and funnel. Column C has drop down list for filtering. Filtering column C gives the proper filtered row, but on selecting no filter in dropr down list, the previous filters are not remembered and entire data is displayed.

Suppose I filter Column A with value 'a' and filter criteria 'Equal To'. It will give 2 rows:

ColumnA    ColumnB    ColumnC
------------  -------------  -------------
     a                b                c
     a                e                f

Now if I filter Column C with drop down list by selecting 'c' it will give 1 row:

ColumnA    ColumnB    ColumnC
------------  -------------  -------------
     a                b                c

Now if I select 'No Filter' in the Column C drop down , it gives all 3 rows as the initial grid, but I want the grid with last filter applied i.e:

ColumnA    ColumnB    ColumnC
------------  -------------  -------------
     a                b                c
     a                e                f

My code in the customdropdown list class that extends the GridTemplateColumn class where actual filtering is fired:

protected

void list_SelectedIndexChanged(object sender, EventArgs e)

 

{

 

DropDownList ddlFilter = sender as DropDownList;

 

 

 

if (ddlFilter.SelectedIndex == 0)  //My 'No Filter' option is at the top of the list

 

{

 

//First index is no filter. we need to clear all filters here.

 

 

RadGrid ragpeopleManagement = (RadGrid)((DropDownList)sender).Parent.Parent.Parent.Parent.Parent.Parent;

 

 

foreach (GridColumn column in ragpeopleManagement.MasterTableView.Columns)

 

{

column.CurrentFilterFunction =

GridKnownFunction.NoFilter;

 

column.CurrentFilterValue =

String.Empty;

 

}

ragpeopleManagement.MasterTableView.FilterExpression =

String.Empty;

 

ragpeopleManagement.MasterTableView.Rebind();

}

 

else

 

{

 

//GridFilteringItem filterItem = ((DropDownList)(sender)).NamingContainer as GridFilteringItem;

 

 

GridFilteringItem filterItem = (GridFilteringItem)((DropDownList)(sender)).NamingContainer;

 

filterItem.FireCommandEvent(

"Filter", new Pair("EqualTo", this.UniqueName));

 

}

}


Pls advice how to retain the previous filters in the grid even  after selecting 'No Filter' in the drop down list filter column.


    

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 03 Apr 2009, 12:31 PM
Hello Nilanjan,

To attain the functionality you are searching for you need to clear only the applied filter from the DropDownList to the FilterExpression property.
Also you do not need to clear CurrnetFilterFunction and CurrentFilterValue for all columns.

Please give a try and let me know how it goes.

Regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Nilanjan
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or