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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s