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

[Solved] Filtering on lookup fields

2 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dan Miser
Top achievements
Rank 1
Dan Miser asked on 05 Mar 2011, 09:56 PM
I have the MVC grid displaying a lookup field similar to this:
<%= Html.Telerik().Grid(Model)
        .TableHtmlAttributes(new { style = "table-layout:fixed" })
        .Name("MachinesGrid")
        .DataKeys(keys => keys.Add(c => c.Id))
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
        .DataBinding(dataBinding => dataBinding.Server()
        .Select("Index", "Machine")
        .Insert("Insert", "Machine")
        .Update("Save", "Machine")
        .Delete("Delete", "Machine"))
        .Columns(columns =>
        {
            columns.Bound(m => m.Name).Width(150);
            columns.Bound(m => m.LocationId);
         })
         .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .Pageable()
        .Sortable()
        .Filterable()
%>

I have a DisplayTemplate called Location.ascx that looks like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int?>" %>
<%  var x =
        ((IEnumerable<SelectListItem>) ViewData[ViewData.ModelMetadata.PropertyName])
        .Where(l => l.Value == Model.ToString())
        .Select(l => l)
        .SingleOrDefault();
%>
<%: x == null ? "" : x.Text %>

The result is that the grid displays the name of the location foreign key perfectly. But when filtering, the value edit control is only allowing me to type numbers. If I type in the id value for a given location, it will filter, but that is more than a little complicated for users.

What do I need to do in order to type the names that are displayed in the location column drive the filtering in the grid?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Dan Miser
Top achievements
Rank 1
answered on 08 Mar 2011, 09:58 PM
Does anyone have any ideas here? Thanks much.
0
Alex Gyoshev
Telerik team
answered on 10 Mar 2011, 02:43 PM
Hello Dan Miser,

Since you are binding the column to an integer, the filtering UI will be for integers. You can either bind it to the location string (say, by using a DTO) or leave it as-is and provide a custom filtering UI that uses the filtering API.

Kind regards,
Alex Gyoshev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Dan Miser
Top achievements
Rank 1
Answers by
Dan Miser
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or