Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 99250

Include Current Item in Server Side Filter

$
0
0

I got a problem with the Kendo UI MVC DropDownList. I want to do server side filtering. When I click on the control, the list gets populated. This works fine if the current selected item is in the populated list.

But what if I have an address book and the current selected name is "Zorro". I have thousands of names before and when I click on the list, only the first 10 names starting with "A" are shown.

How do I include the currently selected item in the DataSource, so it remains selected if I click on the dropdownlist?

Here is my code:

Razor:

@(Html.Kendo().DropDownListFor(m => m.Id)
        .DataValueField("Id")
        .DataTextField("DisplayName")
        .Filter("contains")
        .DataSource(source =>
        {
            source.Read(read =>
            {
                read.Action("PopulateNames", "PhoneBook");
                read.Type(HttpVerbs.Post);
            })
            .ServerFiltering(true);
        })
)

Controller:

[HttpPost]
publicActionResult PopulateNames(stringtext)
{
    var q = TblName.Query(n => n.ClientId.IsEqualTo(Manager.One.ClientId), n => n.DisplayName.Asc());
    if(text != null&& text.Length > 2) q.Filter(n => n.c.DisplayName.IsLike(text));
    q.Top(10);
 
    var rows = q.FetchList<NameLookupViewModel>();
    rows.Insert(0, NameLookupViewModel.Default);
 
    returnJson(rows);
}

Viewing all articles
Browse latest Browse all 99250

Latest Images

Trending Articles



Latest Images