Passing filter to Ajax-Bound Grid manually

2 posts, 0 answers
  1. Matthias
    Matthias avatar
    2 posts
    Member since:
    Nov 2016

    Posted 15 Nov 2016 Link to this post

    Hi,

    Currently I'm facing some problems while passing customn filters via js in an ajax bounded grid.

    The Grid is defined identically to this:

    01.@(Html.Kendo().Grid<ViewModel>()
    02.    .Name("Grid")
    03.    .Columns(columns =>
    04.    {
    05.        columns.Bound(m => m.Name)
    06.            .Filterable(false)
    07.            .Width(150)
    08.            .Title("Name")
    09.    })
    10.    .Pageable(page => page
    11.        .Refresh(true)
    12.        .PageSizes(true)
    13.    )
    14.    .Sortable()
    15.    .Scrollable(s => s.Enabled(true).Height("100%"))
    16.    .DataSource(dataSource => dataSource
    17.        .Ajax()
    18.        .PageSize(10)
    19.        .Read(read => read.Action("Action", "Controller", new { Area = "Area" })
    20.        )
    21.   )

     

    Aftzer the Data is loaded, I want to manually pass a filter from an external function like:

    1.var x = $("#Grid").data("kendoGrid");
    2.x.dataSource.filter({logic: "and", filter: {field: "Name", operator: "eq", value:"John"} });

     

    The defined action of the grid is fired but the POST-Request catched via Dev-Tools doesn't contain the filter (filter =""). 

    The goal is to transport a costum filter during the paging and sorting. (Using Kendos Server-Side-Filtering isn't an option because 

    of architecture-issues)

    How can i include the filter in the request or is there any other way to achieve the described goal?

     

    Thanks.

     

    Regards,

    Matthias

     

     

  2. Matthias
    Matthias avatar
    2 posts
    Member since:
    Nov 2016

    Posted 15 Nov 2016 Link to this post

    Ah okay, solved it by myself:

    Syntax must either be

    x.dataSource.filter({field: "Name", operator: "eq", value:"John"});

     

    or

    x.dataSource.filter({logic: "and", filters: [{field: "Name", operator: "eq", value:"John"}]});

     

    Regards,

    Matthias

Back to Top