Grid Custom Filter with Preset value

3 posts, 0 answers
  1. RICHARD
    RICHARD  avatar
    3 posts
    Member since:
    Mar 2016

    Posted 03 May Link to this post

    Hello, 

    I have a column in my Grid with a custom filter which has pre-populated values in a dropdown. When user opens the page I want the default value to be set to a value that I pass from the Controller in ViewData. I'm able to set the grid filtered to a value on page load but the dropdown in the filter does not have the value selected.

    Grid has the below column

     columns.Bound(c => c.DealYear).Filterable(filterable => filterable.UI("yearFilter")).Width(70);

    with the below options set

    .Filterable(filterable => filterable
            .Extra(false)
            .Operators(operators => operators
               .ForString(str => str.Clear()
                   .StartsWith("Starts with")
                   .IsEqualTo("Is equal to")
                   .IsNotEqualTo("Is not equal to")
               ))
            )

     

    And on page load I filter the grid with a value passed from Controller  - This works fine.

      .Filter(f =>f.Add(p => p.DealYear).Equals(ViewData["DealYear"]))

     

    But in my javascript, how do I set the value to the Filter Dropdown?

    function yearFilter(element) {
            element.kendoDropDownList({
                dataSource: {
                    transport: {
                        read: "@Url.Action("FilterMenuCustomization_DealYear")"
                }
            },
                optionLabel: "--Select Year--"
            });
        }

     

    The page loads with a predefined filter but the dropdown in the Filter shows 'Select Year'.

     

    Thanks!

  2. Milena
    Admin
    Milena avatar
    224 posts

    Posted 04 May Link to this post

    Hello,
     
    Could you verify if this demo presents the desired behavior? I would recommend you to follow the approach of the example in order to achieve the same behavior. In case you would like another solution, could you explain in detail the expected result?

    Regards,
    Milena
    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. RICHARD
    RICHARD  avatar
    3 posts
    Member since:
    Mar 2016

    Posted 04 May in reply to Milena Link to this post

    Hello,

    Thank you for your reply. I have fixed the problem by changing the Equals to IsEqualTo in the Filter.

     .Filter(f =>f.Add(p => p.DealYear).IsEqualTo(Convert.ToInt32(ViewData["DealYear"])))

Back to Top