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.

14 comment(s)
David Compton

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.

13 March, 2008
Mehul Harry (DevExpress)

Hello David,

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

s.RemoveItem(1);

Thanks.

13 March, 2008
drew..

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..  ☻

14 March, 2008
Diego Presno

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

14 March, 2008
drew..

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

14 March, 2008
Mehul Harry (DevExpress)

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

14 March, 2008
Mehul Harry (DevExpress)

Hey Drew,

No worries.Smile

14 March, 2008
drew..

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

14 March, 2008
Roman

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...

8 April, 2009
Mehul Harry (DevExpress)

Hi Roman,

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

8 April, 2009
Weblog @ Rebex.cz :: Honza Šotola

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

20 October, 2010
jssam

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..

13 October, 2011
Mehul Harry (DevExpress)

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

13 October, 2011
kris Degruytere

i found out when inserting the '(All)' item in a gridviews'  GridViewDataComboBoxColumn worked fine but .. gave me 2 times the '(ALL)' option when i selected (ALL).

so i added a checker to check first if it's not there yet..

theeditor.ClientSideEvents.Init = "function(s,e) { if (s.listBox.GetItem(0).text !='(ALL)') {   s.InsertItem(0, '(ALL)', ''); }}"

hope this helps.

24 July, 2013

Please login or register to post comments.