RadGrid - how to assign datasource of column filter programmatically

2 posts, 0 answers
  1. John Pollicino
    John Pollicino avatar
    2 posts
    Member since:
    Dec 2009

    Posted 22 Jul 2015 Link to this post

    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?

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2447 posts

    Posted 27 Jul 2015 Link to this post

    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
Back to Top