In this post we will see the way to work with Kendo UI Mobile ListView control and OData. Before you go ahead with this post, I recommend you to read Creating First Windows Phone Application using Kendo UI mobile and PhoneGap or Cordova
Using ListView
We can use a ListView control as following. You need to explicitly set data-role for Ul HTML element as listview
Resultant listview would be rendered as following in Windows Phone emulator
We can create Grouped ListView as following. We need to specify data-type as group.
Resultant listview would be rendered as following in Windows Phone emulator
If we want to make ListView items as link we can do that as following .
Resultant listview would be rendered as following in Windows Phone emulator
Working with OData
We are going to fetch movies details form OData feed of Netflix. OData feed if Netflix is available at
http://odata.netflix.com/Catalog/Titles
Very first we need to create datasource from OData feed. Datasource from OData feed can be created as following
While creating datasource , we are specifying URL of OData feed , type and pagesize need to be fetched from Netflix server. After datasource being created we need to set template and datasource of ListView as following.
$("#lst").kendoMobileListView( { template: "<strong>${data.Name}<br/><a href= ${data.Url}></a></strong><br/><img src=${data.BoxArt.MediumUrl} alt=a />", dataSource: data }); });
In above code snippet we are setting datasource and template. Template can have HTML elements. Any variable data can be fetched as $datasourcename.fieldname
Complete code is as following. We are having two ListViews on the view to display. First ListView is fetching data from OData feed and second ListView is having hard coded data.
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <title>Cordova WP7</title> <!-- <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8"/>--> <link rel="stylesheet" href="styles/kendo.mobile.all.min.css" type="text/css"/> <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/kendo.mobile.min.js"></script> <script type="text/javascript"> $(document).ready(function () { var data = new kendo.data.DataSource({ type:"odata", // specifies data protocol pageSize:10, // limits result set transport: { read: "http://odata.netflix.com/Catalog/Titles" } }); $("#lst").kendoMobileListView( { template: "<strong>${data.Name}<br/><a href= ${data.Url}></a></strong><br/><img src=${data.BoxArt.MediumUrl} alt=a />", dataSource: data }); }); </script> </head> <body> <div id="firstview" data-role="view" data-transition="slide"> <div data-role="header">First View Header</div> Hello World First View <br /> <ul id="lst" data-role="listview" > </ul> <ul data-role="listview" data-type="group"> <li> Bloggers <ul> <li><a href="#debugmode">debugmode</a></li> <li><a href="#sqlauthrity">SqlAuthority</a></li> </ul> </li> <li> MVP <ul> <li><a href="https://twitter.com">Jacob</a></li> <li><a href="https://twitter.com">Mahesh</a></li> </ul> </li> </ul> <div data-role="footer">First View Footer</div> </div> <script type="text/javascript"> var app = new new kendo.mobile.Application(); </script> </body> </html>
In Windows Phone emulator we should be getting output as following
In this way we can work with Kendo UI ListView control. I hope this post is useful. Thanks for reading.
Follow @debug_modeFiled under: PhoneGap, Telerik, Windows Phone Dev Tagged: Cordova, Kendo UI Mobile, KendoUI, PhoneGap, Telerik, Windows Phone