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

PostBack after my client side filter is resetting my filter selection

5 Answers 220 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 08 Jun 2011, 05:04 PM
Hi

I have a ComboBox filter in a grid that has an 'All' state, which is the default.

I have written some client side code to invoke a filter operation on my grid, and it filters
just fine if I select.

However after the postback occurs my Combo has the 'All' item selected.

So I can never trigger a client side event to revert my grid to unfiltered.

Helpppppppp

5 Answers, 1 is accepted

Sort by
0
Gimmik
Top achievements
Rank 1
answered on 08 Jun 2011, 08:03 PM
Hi Tim,

There are a few ideas I have that may help. For starters, is it possible for you to use the built-in filtering for RadGrid? That will greatly simplify the problem and ensure that your application remains manageable as it grows.

If you need to use a RadComboBox for filtering, I would change the logic of selecting the "All" item. By default, the RadComboBox should persist its last selection after postback unless you override that logic. You could store the last selection and reselect it when the OnClientLoad event fires, but that's an infinite loop waiting to happen since that would also fire the OnClientSelectedIndexChanged event.

If "All" is the first item in the RadComboBox (Item 0) it should be selected by default the first time, and then the previous selection should persist through postbacks.

Let me know if that works for you,
-Gimmik
0
Tim
Top achievements
Rank 1
answered on 08 Jun 2011, 08:19 PM
Hmmm I wonder if you aren't quite understanding the problem I am seeing.

I'm certainly not understanding the response. :-)

Let me try to explain further.

I have a Rad Grid that contains a column that just presents images. The only Filter control
that seems to present correctly is the ComboBox.

I have populated everything successfully. The first item in the Combo is representing my 'All" state,
and you are correct, it is selected by default.

When I select a different filter item in the combo I have a client side selection change event fire.
I can see it fires because I put and alert in the script block.

Briefly the text in the combo changes to the correct value and I trigger a tableview.filter on the grid.

This filters the rows I see in the grid to what I want to see.

However after the postback that occurs the combobox appears to be back in my 'All' state.
So clicking on that item DOESN'T trigger my client-side event handler. So I cann't issue a tableview.filter 
call with the NoFilter parameter as I had hoped.

TIA    
0
Gimmik
Top achievements
Rank 1
answered on 09 Jun 2011, 05:58 PM
Hi Tim,

I'm not sure why the RadComboBox is responding like that. You're best bet for an answer would be to submit your project to Telerik support. They'll be able to tell you why the control is behaving like that.

But, let's think outside the box for a moment and see if we can't find an acceptable workaround. What about adding another default item to the RadComboBox server-side when the page loads the first time. Set the text of the item to "-- Select a Filter --" That way you will be able to select "All" (perhaps rename that to "No Filter") and the OnClientSelectedIndexChanged will fire. It's not ideal but it should work.

Let me know what you think, I have a few other more complicated workarounds that you could try as well.

-Gimmik
0
Tim
Top achievements
Rank 1
answered on 09 Jun 2011, 06:51 PM
Hi Gimmik

Somebody here suggested I have an empty item as my default and add an 'All' item as an additional item.

That would at least allow me to return the grid to an unfiltered state.

But that doesn't address the real problem that the combo used in the filter template doesn't
indicate my current filter state. So the UI is inconsistent.  

I did just find an article on your site the actually was to do with interelated combboxes, that were not being
used as a filter.

The thread was titled, 'related combobox values on postback'.

It talks about setting the AllowCustomText property of the Combobox, disabling input,
and finally doing on demand loading and highlighting of the appropriate item on the combobox dropdown opening event.

While I wonder if this would solve my problem I am curious as to why it would take that much effort.

I saw comments that Enabling View state and ViewStateMode should have solved my problem, it didn't.

In the end I have implemented Custom filtering, as show in one of your examples.

This gives me the behavior I need but this whole problem seems to have a much more complicated
solution that I would have expected. I am a novice at this so there is a lot I don't know.

Sorry for the long response, but I'm still hoping someone will point out the simple solution I missed.

TIA
0
Gimmik
Top achievements
Rank 1
answered on 09 Jun 2011, 07:20 PM
Hi Tim,

I'm glad you found a solution that worked for you. Normal behavior for the RadComboBox is to preserve the state through postback. I'm not sure why that behavior was being broken in your application. The other method I was going to suggest was manually saving and preserving the selection. You would also have to cancel the OnClientSelectedIndexChanged event that would get fired after the load, but it's alother option. If you get an answer as to why the state of the RadComboBox was being lost, please let me know.

-Gimmik
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Gimmik
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Share this question
or