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

MVC ListView Filter

3 Answers 696 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Stephen Graham
Top achievements
Rank 1
Stephen Graham asked on 20 Jun 2013, 03:24 PM
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.

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 20 Jun 2013, 03:54 PM
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!
0
Stephen Graham
Top achievements
Rank 1
answered on 20 Jun 2013, 04:01 PM
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>
0
Stephen Graham
Top achievements
Rank 1
answered on 20 Jun 2013, 05:47 PM
I shall answer myself. I'd missed the # in the $('#SearchBox')

working fine now.
Tags
ListView
Asked by
Stephen Graham
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Stephen Graham
Top achievements
Rank 1
Share this question
or