MVC ListView Filter

4 posts, 0 answers
  1. Stephen Graham
    Stephen Graham avatar
    7 posts
    Member since:
    Sep 2012

    Posted 20 Jun 2013 Link to this post

    Is it possible to filter an MVC Listview based on text entered into a textbox? if so how would one go about doing so?

    for example a listview that returns over 400 records, and needs to be searchable.

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 20 Jun 2013 Link to this post

    Hello Stephen,

    Using DataSource.filter you can reduce the amount of items listed in the ListView widget. 

    Regards,
    Nikolay Rusev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Stephen Graham
    Stephen Graham avatar
    7 posts
    Member since:
    Sep 2012

    Posted 20 Jun 2013 Link to this post

    ok, I have some code. It's trying to filter but giving me the error  "Invalid property or
    field - 'undefined' for type: list_result Source: Kendo.Mvc Method:
    System.Linq.Expressions.Expression
    CreateMemberAccessExpression(Kendo.Mvc.Infrastructure.Implementation.Expressions.IMemberAccessToken,
    System.Linq.Expressions.Expression) "


    Code: 
    @Html.TextBox("SearchBox") <button id="btnSearch">Filter</button>
    <script>
    $('#btnSearch').on("click", function (e) {

    refreshList();

    return false;

    });

    function refreshList() {
    $filter = new Array();
    $filter.push({ field: "searchname", operator: "contains", value: $('SearchBox').val() });

    var list = $("#listView").data("kendoListView");
    list.dataSource.filter($filter);

    }
    </script>
    <div class="clientList">
    @(Html.Kendo().ListView<MyModel>(Model)
    .Name("listView")
    .TagName("div")
    .ClientTemplateId("template")
    .DataSource(dataSource =>
    {
    dataSource.Read(read => read.Action("MyAction", "MyController"));
    dataSource.PageSize(15);
    })
    .Navigatable()
    .Pageable()

    )
    </div>
  5. Stephen Graham
    Stephen Graham avatar
    7 posts
    Member since:
    Sep 2012

    Posted 20 Jun 2013 Link to this post

    I shall answer myself. I'd missed the # in the $('#SearchBox')

    working fine now.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready