Blogs

News

Email Subscriptions

Mehul Harry's DevExpress Blog

ASPxGridView: Improve Filter by Adding an '(All)' item

     

Here is useful tip that can help you improve user experience. When filtering the ASPxGridView with an ASPxComboBox, you can add a new item to the top labeled "All". This can be useful when filtering because the word All is more descriptive than leaving a blank item. You can see an example of this item used on the grid used for the tutorials site:

image

So what's the trick? Just add a null ListEditItem to the ASPxComboBox. The new (All) item will be inserted above the default blank line that's on the top of the list. It does the same thing, but describing the functionality by changing the name really helps the user. So now you and the users can select the new "All" item to clear filtering for the column. To add this item, override the AutoFilterCellEditorInitialize method as follows:

protected void ASPxGridView1_AutoFilterCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
   if (e.Column.FieldName == "Country")
   {
      ASPxComboBox comboBox = e.Editor as ASPxComboBox;
      comboBox.ClientSideEvents.Init = "function(s, e) {s.InsertItem(0, '(ALL)', '');}";
   }
}

First, identify which columns use an ASPXCombobox then add the lines shown above. Now when the filter cell is initialized, the new "All" item will be added.

Enjoy and thanks.

Published Mar 13 2008, 02:24 PM by Mehul Harry (DevExpress)
Filed under:
Technorati tags: ASPxGridView
Bookmark and Share

Comments

 

David Compton said:

I implemented your suggestion and the ALL item appears and works well.  However the blank line still appears below the ALL item - this is for a GridViewDataCheckColumn that only has 2 values to select from - Checked or Unchecked.

March 13, 2008 8:46 PM
 

Mehul Harry (DevExpress) said:

Hello David,

To remove the blank line at the second position, add this line after the InsertItem:

s.RemoveItem(1);

Thanks.

March 13, 2008 9:51 PM
 

drew.. said:

Thanks Harry, nice tip. I hear this whispering in the background: "bring me in coach, bring me in, i wanna play, i wanna play.... make me a real property within the columns object, please coach, oh please?" .

i swear i heard that..  ☻

March 14, 2008 12:26 AM
 

Diego Presno said:

Great idea,

Talking about filters.. wouldn't be nice that when using the "%" to filter, the grid detect that character and not run the query?

The result of it is that the grid deletes your "%" char before you typed anything

March 14, 2008 10:10 AM
 

drew.. said:

...ahhhh geeez, sorry.. Mehul, my bad with the Harry thing..

March 14, 2008 10:55 AM
 

Mehul Harry (DevExpress) said:

Thanks Diego,

The "%" character is used as a wildcard. So if you don't put something like "%SOMETEXT%" then a single wildcard will be removed because it's already showing all the records. You can read more here: http://tinyurl.com/2sqf8x

March 14, 2008 5:41 PM
 

Mehul Harry (DevExpress) said:

Hey Drew,

No worries.Smile

March 14, 2008 5:43 PM
 

drew.. said:

as an OT aside.. that tinyurlcom link usage is very interesting.. thanks!

March 14, 2008 10:39 PM
 

Roman said:

To identify check box column I use

.......

if (e.Column.GetType().Name.Equals("GridViewDataCheckColumn"))

.......

which is better than explicit column's name in your sample...

April 8, 2009 5:51 PM
 

Mehul Harry (DevExpress) said:

Hi Roman,

Thanks for the tip. I may include it in a future video. Smile

April 8, 2009 7:00 PM
 

Weblog @ Rebex.cz :: Honza Šotola said:

Možná zase objevuji Ameriku, ale následující feature jsem neznal. Jistě jste v různých projektech řešili

October 20, 2010 8:39 AM
 

jssam said:

any chance this will be implemented server side via a normal property setting? Ive speant hours today trying to add an All selection to a databound header. nothing worked except this. I do not like work arounds..

October 13, 2011 6:51 PM
 

Mehul Harry (DevExpress) said:

jssam,

Not that I'm aware of but I recommend creating a suggestion in the support center:

www.devexpress.com/.../CreateIssue.aspx

Also, this may help you:

www.devexpress.com/.../B157052.aspx

October 13, 2011 7:04 PM

About Mehul Harry (DevExpress)

Mehul Harry is an ASP.NET technical evangelist at Developer Express. You can reach him directly at mharry@DevExpress.com. You can also follow him on Twitter: http://twitter.com/mehulharry
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.