Kendo UI Listview filter
How to filter the Kendo UI ListView using a 'contains' style search.
by junto
HTML
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.default.min.css">
<script src="http://cdn.kendostatic.com/2014.3.1411/js/kendo.all.min.js"></script>
<div class="panel panel-default">
<div class="panel-heading form-inline">
<div class="form-group">
<label for='search-term'>Search </label>
<input type="text" id="search-term"/>
</div>
</div>
<div class="panel-body">
<div class="demo-section">
<div id="listView"></div>
<div id="pager" class="k-pager-wrap"></div>
</div>
</div>
</div>
<script id="template" type="text/x-kendo-template">
<div class="product">
<img src="http://demos.telerik.com/kendo-ui/content/web/foods/#= ProductID #.jpg" alt="#: ProductName # image" />
<h3>#:ProductName#</h3>
<p>#:kendo.toString(UnitPrice, "c")#</p>
</div>
</script>
CSS
html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }
.demo-section {
width: 400px;
/*margin: 20px auto;*/
border: 0;
background: none;
}
#listView {
padding: 10px 5px;
margin-bottom: -1px;
min-height: 510px;
}
.product {
float: left;
position: relative;
width: 111px;
height: 170px;
margin: 0 5px;
padding: 0;
}
.product img {
width: 110px;
height: 110px;
}
.product h3 {
margin: 0;
padding: 3px 5px 0 0;
max-width: 96px;
overflow: hidden;
line-height: 1.1em;
font-size: .9em;
font-weight: normal;
text-transform: uppercase;
color: #999;
}
.product p {
visibility: hidden;
}
.product:hover p {
visibility: visible;
position: absolute;
width: 110px;
height: 110px;
top: 0;
margin: 0;
padding: 0;
line-height: 110px;
vertical-align: middle;
text-align: center;
color: #fff;
background-color: rgba(0,0,0,0.75);
transition: background .2s linear, color .2s linear;
-moz-transition: background .2s linear, color .2s linear;
-webkit-transition: background .2s linear, color .2s linear;
-o-transition: background .2s linear, color .2s linear;
}
.k-listview:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
JavaScript
var dataSource = new kendo.data.DataSource({
pageSize: 9,
transport: {
read: {
//using jsfiddle echo service to simulate JSON endpoint
url: "/echo/json/",
dataType: "json",
type: "POST",
data: {
// /echo/json/ echoes the JSON which you pass as an argument
json: JSON.stringify([{"ProductID":1,"ProductName":"Chai","SupplierID":1,"CategoryID":1,"QuantityPerUnit":"10 boxes x 20 bags","UnitPrice":18,"UnitsInStock":39,"UnitsOnOrder":0,"ReorderLevel":10,"Discontinued":false,"Category":{"CategoryID":1,"CategoryName":"Beverages","Description":"Soft drinks, coffees, teas, beers, and ales"}},{"ProductID":2,"ProductName":"Chang","SupplierID":1,"CategoryID":1,"QuantityPerUnit":"24 - 12 oz bottles","UnitPrice":19,"UnitsInStock":17,"UnitsOnOrder":40,"ReorderLevel":25,"Discontinued":false,"Category":{"CategoryID":1,"CategoryName":"Beverages","Description":"Soft drinks, coffees, teas, beers, and ales"}},{"ProductID":3,"ProductName":"Aniseed Syrup","SupplierID":1,"CategoryID":2,"QuantityPerUnit":"12 - 550 ml bottles","UnitPrice":10,"UnitsInStock":13,"UnitsOnOrder":70,"ReorderLevel":25,"Discontinued":false,"Category":{"CategoryID":2,"CategoryName":"Condiments","Description":"Sweet and savory sauces, relishes, spreads, and seasonings"}},{"ProductID":4,"ProductName":"Chef Anton's Cajun Seasoning","SupplierID":2,"CategoryID":2,"QuantityPerUnit":"48 - 6 oz jars","UnitPrice":22,"UnitsInStock":53,"UnitsOnOrder":0,"ReorderLevel":0,"Discontinued":false,"Category":{"CategoryID":2,"CategoryName":"Condiments","Description":"Sweet and savory sauces, relishes, spreads, and seasonings"}},{"ProductID":5,"ProductName":"Chef Anton's Gumbo Mix","SupplierID":2,"CategoryID":2,"QuantityPerUnit":"36 boxes","UnitPrice":21.35,"UnitsInStock":0,"UnitsOnOrder":0,"ReorderLevel":0,"Discontinued":true,"Category":{"CategoryID":2,"CategoryName":"Condiments","Description":"Sweet and savory sauces, relishes,...