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

Combo box filters

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 20 Jul 2009, 10:56 AM
Hi,

I'd like to have a filter that uses a combo box instead of the normal text box.  I've seen two different examples of this on the site as the Google style filtering and then another one using Countries as the datasource for it.

Both methods are horrible in the amount of effort that they will require to implement and then maintain.  I have seen that the DevExpress grid has the feature and it is pretty much a case of setting a flag on the grid to show the drop down.

Have I missed something in the demos etc and is there an easy way to do this?  I'm not afraid of hard work but would have thought that a simple way to do this would have been part of the RAD approach.

Regards,

Jon

2 Answers, 1 is accepted

Sort by
0
Accepted
ManniAT
Top achievements
Rank 2
answered on 20 Jul 2009, 12:53 PM
Hi Jon,

AFAIK a little bit of code is neede to implement CB Sorting.
I always use the approach with the codeblock in the filtertemplate.
<FilterTemplate> 
    <telerik:RadComboBox Width="160px" ID="rcbKulturkreisFilter" DataSourceID="odsKulturkreise" DataTextField="Name" DataValueField="ID" Height="200px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("KulturkreisID").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="KKFilterIndexChanged" DropDownWidth="240px">  
        <Items> 
            <telerik:RadComboBoxItem Text="Alle" /> 
        </Items> 
    </telerik:RadComboBox> 
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
        <script type="text/javascript">  
            function KKFilterIndexChanged(sender, args) {  
                var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");  
                tableView.filter("KulturkreisID", args.get_item().get_value(), "EqualTo");  
            }  
        </script> 
    </telerik:RadScriptBlock> 
</FilterTemplate> 

And yes I also had to work with a control which offers "autocombofiltering".
My problem there was in some situations I got hundreds of entries in this combobox.
And it was almost impossible to remove them.

With the telerik this solution I have to write a bit of code BUT
a.) I didn't develope this code - I found it in the forum (so 5 minutes search - copy and paste)
b.) It's always the same pattern - copy and paste again :)
c.) it's totally customizable

For c.) and my "hundreds of entries" I built a simple function (server side) which extracts the first x letters from the possible values.
That was my datasource for the filter listbox. And as operator I used StartsWith - done.

I also have a filter with contains as criteria - so I can filter for an example for "eggs" and find "easter eggs, rotten eggs, colored eggs with...).

I don't know if the controls you're talking about has the ability to do things like this - RadGrid does.
The price for it - 5 lines of (copy and paste) code.
And if you really need it often - it should be possible to build a user control for this job.
Which should result in adding a filtertemplate with exactly that control and passing an ID to it.

Last not least - yes there are situations where I also would like to have an "autocombofilterflag" :)

Regards

Manfred
0
Jon
Top achievements
Rank 1
answered on 20 Jul 2009, 03:08 PM
Hi Manfred,

Thanks for the help on that - this is a much simpler way of doing it than the other examples that I saw.

I think that the DevExpress grid does everything for you on the filtering front and will only show entries that are relevant - you don't need to hook up extra datasources and all that.  I'd be great if the guys at Telerik could implent something of that sort into the grid. 

I think I'll try the custom control route as I'll need quite a few of these as well as some date range filters.  Should be fun ;)

Thanks for the help,

Regards,

Jon
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
ManniAT
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or