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

RadGrid Custom Filtering

2 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kpat154
Top achievements
Rank 1
kpat154 asked on 29 Oct 2008, 04:33 PM
I have a need to make minor customizations to the filtering logic in RadGrid for my app. My needs are fairly simple: I have a particular column that's making use of the DataFormatString to display a user friendly representation of a float and I need to intercept the filter command on that column to reformat the user's input so that it matches the underlying datastore rather than the value presented in the GUI.

This sort of thing is very common. So much so that I'm shocked at how little support for it there is in the grid. According to the documentation (here), in order to accomplish this you must do the following:
  1. Subscribe to the ItemCommand event
  2. Determine whether or not the command being fired is a filter command
  3. Determine whether or not the filter command matches a given column
  4. If so, string parse the entire sql where clause used by the grid so that you can parse out the particular predicate you're interested in
  5. Then, string parse the predicate to access the given value you want to reformat
  6. Reformat that value and replace it in the where clause
  7. Store the reformatted where clause somewhere because you'll then have to...
  8. Subscribe to the NeedDataSource event
  9. Replace the grid's default FilterExpression with your custom version
This is very bad. Surely there's a less error prone way to accomplish this task. I expected to find a separate FilterExpression object for each column with members for FilterType and FilterValue which could then be modified on ItemCommand. Am I missing something?

-K



2 Answers, 1 is accepted

Sort by
0
kpat154
Top achievements
Rank 1
answered on 30 Oct 2008, 09:36 PM
Anyone have a comment on this issue? Is string parsing the only solution to this problem or does Telerik provide a more robust option?
0
Rosen
Telerik team
answered on 03 Nov 2008, 09:35 AM
Hello,

In order to achieve the requested functionality you can simply replace the filter textbox's value with the one you want to filter on. This can be accomplished in ItemCommand event. I have attached a simple page which demonstrates a basic implementation of this approach.

Please give it a try and let us know if this helps.

Greetings,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
kpat154
Top achievements
Rank 1
Answers by
kpat154
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or