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

Passing filter to Ajax-Bound Grid manually

1 Answer 354 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthias
Top achievements
Rank 1
Matthias asked on 15 Nov 2016, 10:28 AM

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

 

 

1 Answer, 1 is accepted

Sort by
0
Matthias
Top achievements
Rank 1
answered on 15 Nov 2016, 12:12 PM

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

Tags
Grid
Asked by
Matthias
Top achievements
Rank 1
Answers by
Matthias
Top achievements
Rank 1
Share this question
or