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

Grid Custom Filter with Preset value

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RICHARD
Top achievements
Rank 1
RICHARD asked on 03 May 2016, 05:10 PM

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 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 04 May 2016, 08:58 AM
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
0
RICHARD
Top achievements
Rank 1
answered on 04 May 2016, 01:55 PM

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"])))

Tags
Grid
Asked by
RICHARD
Top achievements
Rank 1
Answers by
Milena
Telerik team
RICHARD
Top achievements
Rank 1
Share this question
or