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

AutoPostBackOnFilter behavior when using between (and more)

5 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 08 Jan 2010, 03:46 PM
I'm having a hard time understanding the decisions that lead to the current filter behavior. Essentially without doing a bunch of custom coding you get 2 options, neither of which are perfect.

You can either leave AutoPostBackOnFilter as false which requires the end user to either click a filter icon, or select a filter type. Or you get the set this true and get the auto postback which works for most examples well. I really beleive there should be a third option which removes the auto post back on defocus of the filter input. Here's why.

Set AutoPostBackOnFilter to true, and try to use the between filter on a date field. Here's how it went for me.

1. Enter two dates seperated by a space
2. Move mouse to select between fiter
3. Page posts back and throws a "String was not recognized as a valid DateTime" exception.

So, start again:
1. Select the between filter
2. Page posts back, sees the filter is blank and resets the filter value to blank again
3. Goto process 1

So, the only way to get these 2 to work together that I have discovered is to do this:
1. Enter 2 dates seperated by space
2. Unfocus
3. Let the page post back, throw an exception
4. Hit the back button
5. previous page displays, with filter data in field, unfocused
6. Select between filter
7. Page posts back and shows the correct data filtered

Please tell me I'm really missing something here. My end users are not going to want to see an exception like that. Nor do I want to trap the exception and hide it for when they do put crap into the text field.

Wouldn't it make some sense to have a few different options for how to deal with filters. For instance removing the onBlur postback behavior, or adding a search button. Seems to me both of these would require custom programming at this point. But I'd really like to see both become part of the core package.

In addition, it seems to me tht it would make a lot of sense to preserve the selection of the filter type, even if the filter field was blank. Then the end user could go about his business either way, by selecting a filter first, or entering data into the field first.

So for now, can somone give me some insight on how I might go about removing the onBlur auto post back behavior. I really like the hit enter to filter behavior and want to keep that.

Thank you in advance.

5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 12 Jan 2010, 03:29 PM
Hello James,

In order to remove the onblur functionality, you should:

1. Attach an event handler to the ItemCreated event of the grid.

2. Find the filtering box or control for the corresponding column.

3. Remove its "onchange" attribute.

For example, if you have a BoundColumn of type System.DataTime then your code for the above steps becomes as follows:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{        
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem item = e.Item as GridFilteringItem;  
       TextBox dateInput = item["ColumnUniqueName"].FindControl("FilterTextBox_ColumnUniqueName") as TextBox;
        dateInput.Attributes.Remove("onchange");
    }
}

If you encounter any difficulties for the above steps, please, paste your mark-up for the date-time column and I will assist you with implementing the scenario in question.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
James
Top achievements
Rank 1
answered on 18 Jan 2010, 05:05 PM
This was effective at removing the onBlur event from a single filter box.
0
James
Top achievements
Rank 1
answered on 29 Mar 2010, 03:00 PM
The method you describe above will remove the onBlur from a single field. You have to specify the field name explicitly, is there a way to loop through them all and remove every onBlur event without having to know the names of the columns explicitly?
0
James
Top achievements
Rank 1
answered on 29 Mar 2010, 08:39 PM
Okay, I figured out how to do this on my own. I'll share code if someone is interested. But the side affects of doing this really make it not worth it.

I still want someone to explain to me how the between operator is supposed to work by default. Using the default settings I just can't seem to make it work.
0
Radoslav
Telerik team
answered on 01 Apr 2010, 12:05 PM
Hi James,

I am glad that you achieved the desired functionality. If you share your code, I believe it will be of help for other users.

For more information about between operator and default filtering, please check out the following documentation articles:
http://www.telerik.com/help/aspnet-ajax/grdbasicfiltering.html
http://www.telerik.com/help/aspnet-ajax/grdoperatewithfilterexpression.html

Also when you have filtering on datetime column and between filter, I suggest you to use the filter template instead of using the default filtering. Please check out the following online documentation article and online demo for more information about filter templates:
http://www.telerik.com/help/aspnet-ajax/radgrid-filter-template.html
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

I hope this helps.

Greetings,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
James
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or