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

RadGrid - how to assign datasource of column filter programmatically

1 Answer 258 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dalila Uriarte
Top achievements
Rank 1
Dalila Uriarte asked on 22 Jul 2015, 04:50 PM

I'm trying to set up a RadGrid with column filters that have values from the column itself, as demonstrated in the second RadGrid in this demo page: http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/basic-filtering/defaultcs.aspx

The columns for City, Country, and Contact Title have the functionality I need.

I have a RadGrid running in an ASP.NET Web Forms application, I've set AllowFilteringByColumn to true, and FilterType to "CheckList". I'm setting the datasource of the RadGrid programmatically at runtime to a list of objects. My goal is to set the column filter datasources programmatically at runtime as well, but none of the examples I've seen demonstrate a way to do this. The demo page linked above demonstrates this with a web service, and the column filters are created by referencing one of the web service methods. I don't want a database call for each one of my filterable columns, especially since I gather the necessary values when the page loads. As an example, two of my columns are User and Note Types. I use the following to extract a collection of distinct values:

var userNames = model.Results.Select(r => r.Username).Distinct().OrderBy(name => name);
var noteTypes = model.Results.Select(r => r.NoteType).Distinct().OrderBy(name => name);

I would very much like to simply assign these collections to the column filters in the RadGrid at runtime, rather than developing web services I don't need. Can this be done?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 27 Jul 2015, 07:41 AM
Hi John,

Thank you for contacting us.

When you use CheckList filtering in RadGrid you can handle the server-side OnFilterCheckListItemsRequested event of the grid and provide the data source to the filters within that event. Detailed information on this matter could be found in the following help article:
Please take a look at the example in the help article and if any further questions arise, do not hesitate to contact us again.


Regards,
Konstantin Dikov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Dalila Uriarte
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or