How to change background of View in Kendo UI Mobile

In this post I will show you how we can put a background color in Kendo UI Mobile view. Let us suppose that we got following view

clip_image001

There may be requirement when you will have to change background color of this view. You can change that using CSS as following

clip_image002

You will have to put this CSS on the page. I hope this post was useful. Thanks for reading

Toggle Button Icon and Handler in Kendo UI

While working on an application I come across a requirement to toggle the button in application layout. On clicking of the button, its icon and handler should be toggled with another icon and function. In this post we will learn how to achieve this.

Problem statement

To understand the problem better let us consider following application. You can see that detail of a particular session is displayed in the view. In header there is an Add button. When user click on the Add button, this particular session should get added to Favorite Session List and Add button should get changed to Trash button. Essentially we need to toggle the button with different icon and function attached the click event.

image

Solution

We can toggle from Add to Trash as following

clip_image002

In above code

  • saveButton is id of the button.
  • fsaveDataLocally is name of the function to add Session in Favorite Session List.
  • fremoveDataLocally is name of the function to remove Session from Favorite Session List.

You can bind and unbind handler from your application as per your business requirement.

We can toggle from Trash to Add as following

image

In this way you can toggle icon on Kendo Button and can toggle handler in the run time. I hope this post is useful. Thanks for reading.

 

Working with Kendo Data Model

Kendo.data.model provides the ability to define schema. Inside schema fields with various attributes and methods can be defined. It is inherited from ObservableObject

Read more about it here

You can create Kendo UI Model as following,

image

Even though at first glance above syntax looks verbose but it is very straight forward. You can create a new model by creating a variable of type kendo.data.model

  • First we define identifier of the model. This can be any field of the model. It is defined by setting id attribute
  • Different fields of model can be created in field attribute

For example, if you want to create a model for Student, you can do that as following

image

In Student model

  • There are three fields name , rollnumber and marks
  • Rollnumber is set as identifier field of this model.
  • Type of the fields is set in the type attribute.

You can create object of a model as below.

image

You can controls fields behavior and can configure many details like following

  • Default value can be set
  • Editable behavior can be set
  • Null behavior can be set
  • Default parsing function for a field can be set.
  • Validation rules can be set

You can configure various attributes as following

image

Name filed in the model is created with different attributes. For example this name field is editable and its default value is dj.

You can determine that whether a model is new or not using isNew method. Consider below instance of Student model, you will get false as output. If model identifier is set then Kendo framework does not consider that as new

image

If you change above model as following, you will get true in alert since id of model is not set.

image

In this way you can work with Kendo.data.model. I hope you find this post useful. Thanks for reading.

 

Dynamically Navigating from one View to other in Kendo UI Mobile

While creating application, a very common requirement you may come across is to dynamically navigate from one View to other on basis of some query parameter.

Consider a requirement from below diagram, when you click on a particular session, you need to navigate to session detail view.

image

We can list down the requirement as following

  • We need to fetch Session ID from All Session View and pass it as input parameter to Session Detail view
  • On Session Detail view fetch the data on basis of the Session Id passed from All Session View.
  • Dynamically display Session Detail of a particular Session on Session Detail View.

At very first we need to set the query parameter in Template of All Session View as following. If you notice we are setting Session ID as query parameter in list view link button. On click of the detail button, application will be navigated to SessionDetails view with Session ID as value in query parameter.

image

Next Session Detail View is as below. Data-Show attribute of Session Detail View is set the function sessionDetailsShow. Whenever application will navigate to this view javascript function SessionDetails will be invoked

image

In SessionDetails function view Session ID can be read as following

image

Once you have value of Session ID passed from All Session View on Session Detail view, filter the data source on this Session ID. After fetching filtered data, data can be bind to Session Detail template as following.

image

Above code should be in SessionDetailShow function and you can define Template from Session Detail View as of your requirement

image

This is what all you need to do to do navigate from one view to other with data. I hope this post is useful. Thanks for reading.

Slides and Source Codes to the “Webinar on Creating HTML5/JS Mobile & Web Apps with Kendo UI” available to download

Hi Everyone,

image

Thank you so much for attending Kendo UI webinar yesterday. We had exciting time and hope you found webinar useful. As promised we are making all the resources of webinar available to download.

Download Slides and Source Codes from here

If you missed the webinar then you can start learning about Kendo UI from here . We strongly recommend you to go ahead and download trial version of Kendo UI from here. If you find any difficulties , throw your questions in comment or can directly send mail to us.

 

In this webinar we covered

  • Introduction to Kendo UI
  • Getting started with Kendo UI Web
  • Understanding and using different Kendo UI Web widgets
  • Getting started with Kendo UI Data VIZ
  • Kendo UI widgets on SharePoint web parts
  • Introduction to Kendo UI Mobile
  • Creating Hybrid Mobile application “Movie Explorer”

You can find some resources here to start exploring Kendo UI and can read Kendo UI documents here

If you need any assistance to start with Kendo UI please writes to us. See you soon in next webinar.

Netflix Movie Explorer : A Hybrid Mobile App using Kendo UI Mobile

This post is “Step by Step Illustration of Codes “required to create Netflix Movie Application. You can read a detailed article on same topic here .

image image

image

Step 1 : Add Reference


<meta charset="utf-8" />
 <script src="kendo/js/jquery.min.js"></script>
 <script src="kendo/js/kendo.mobile.min.js"></script>
 <script src="scripts/hello-world.js"></script>
 <link href="kendo/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <link href="styles/main.css" rel="stylesheet" />

Step 2 : Create Layout


<div data-role="layout" data-id="mobile-tabstrip">
 <header data-role="header">
 <div data-role="navbar">
 <a data-role="backbutton" data-align="left">Back</a>
 <span data-role="view-title"></span>
 </div>
 </header>
 <div data-role="footer">
 <div data-role="tabstrip">

 <a href="#loginView" data-icon="action">Login</a>
 <a href="#movieTitleView" data-icon="more">Browse</a>
 <a href="#searchView" data-icon="search">Search</a>
 </div>
 </div>
 </div>

Step 3 : Initialize Kendo Mobile


<script>
 var app = new kendo.mobile.Application(document.body,
 { transition: "slide",
 layout: "mobile-tabstrip",
 initial: "loginView"
 });
</script>

Step 4 : Create Views

 <div data-role="view" id="movieTitleView" data-title="Title" >
 <h1>Movie Title View </h1>
 </div>
 <div data-role="view" id="loginView" data-title="Login" >
 <h1>Login View </h1>
 </div>
 <div data-role="view" id="searchView">
 <h1>Search View</h1>
 </div>

Step 5 : Create Data Source


var movieTitleData;
 movieTitleData = new kendo.data.DataSource(
 {
 type: "odata",
 pageSize: 30,
 endlessScroll: true,
 batch: false,
 transport: {
 read: {
 url: "http://odata.netflix.com/Catalog/Titles",
 dataType: "jsonp",

data: {
 Accept: "application/json"
 }
 }
 }

});
 function showMovieTitle(e) {
 movieTitleData.fetch();
 }

Step 6 : Create Template to show Movies Title


<script id="movieTemplate" type="text/x-kendo-template">
 <a href="\#movieDetailView?Id=#:data.Id#"
 class="km-listview-link"
 data-role="listview-link">
 <h4>#=data.Name.substring(0,15)#</h4>
 <img src= #=data.BoxArt.MediumUrl# />
 </a>
 </script>

Step 7 : Create List View to display Movie Title

<div data-role="view" id="movieTitleView"
 data-title="Title"
 data-show="showMovieTitle" >
 <ul id="movieTitleList"
 data-source="movieTitleData"
 data-endlessScroll="true"
 data-template="movieTemplate"
 data-role="listview"
 data-style="inset">
 </ul>
</div>

Step 8 : Define CSS for Movie Title


<style scoped>
 #movieTitleView
 h4 {
 display: inline-block;
 font-size: 1.1em;
 margin: 1em 0 .5em 1em;
 }

 #movieTitleView
 img {
 float: left;
 width: 4em;
 height: 4em;
 margin: 0;
 -webkit-box-shadow: 0 1px 3px #333;
 box-shadow: 0 1px 3px #333;
 -webkit-border-radius: 8px;
 border-radius: 8px;
 }
 #movieDetailView
 img {
 float: none;
 width: 15em;
 height: 12em;
 margin: 0;
 -webkit-box-shadow: 0 1px 3px #333;
 box-shadow: 0 1px 3px #333;
 -webkit-border-radius: 8px;
 border-radius: 8px;
 }

 </style>

Step 9 : Create Data Source for Movie detail view


var movieTitleData;
movieTitleData = new kendo.data.DataSource(
 {
 type: "odata",
 pageSize: 30,
 endlessScroll: true,
 batch:false,
 transport:{
 read: {
 url: "http://odata.netflix.com/Catalog/Titles",
 dataType: "jsonp",

data: {
 Accept: "application/json"
 }
 }
 }

});

Step 10 : Create Template for Movie detail view


<script id="movieDetailTemplate" type="text/x-kendo-template">
 <h2>#=data.Name#</h2>
 <img src= #=data.BoxArt.LargeUrl# height=1 width=1/></br></br>
 <h4> #=data.Synopsis# </h4>
 <a data-role="button" data-rel="actionsheet" href="\#shareonSocialMediaActionSheet">Share Feedback</a>
 </script>

Step 11 : Create View for Movie detail view


<div data-role="view"

id="movieDetailView"

data-title="Details"

data-show="showMovieDetail" >

<ul data-role="actionsheet" id="Ul1" >

<li><a data-action="functionToShareOnFacebook">Facebook</a></li>

<li><a data-action="functionToShareOnTwitter">Twitter</a></li>

</ul>

</div>

Webinar on Creating HTML5/JS Mobile & Web Apps with Kendo UI

image

I am excited to inform you about coming Webinar on Kendo UI. It is on 25th July 2012 at 3:00 PM. If you are new to Kendo UI, you may find more about it here

image

In this Webinar we will help you to get it started with Kendo UI. We will cover many demos to have a better understanding on the Kendo UI as product. Find below the details to attend the Webinar.

Below is Live Meeting URL to attend the Webinar.

https://www.livemeeting.com/cc/0000000379_116/join?id=9MWM5W&role=attend

Just make sure that Live Meeting client has installed on your machine. In case if you need,

Meeting ID: 9MWM5W

If you find any difficulty in attending the session or need more detail about the Webinar, please send me a mail on

clip_image002

We would like to encourage you , your team to attend the Webinar.

 

Back button styling problem in Kendo UI Mobile

I was creating a sample cross platform mobile application using with KendoUI mobile. I had a back button in the header and it was not rendering as expected .It was rendering like below,

clip_image001

On walking through code I found, I have added css reference twice.

clip_image003

I went ahead and removed duplicate reference. After that I found Back button was rendering as expected.

clip_image004

I hope this small observation will help you in creating your cool applications using Kendo UI Mobile.

 

Setting Development Environment in Visual Studio 2010 using NuGet for KendoUI

Read more about Kendo UI here

Read How to work with NuGet here

In this post we will walkthrough on setting up development environment in Visual Studio 2010 by installing NuGet package of KendoUI. To start with launch Visual Studio and create Web Application project.

image

Now delete Default.aspx, About.aspx,Site.master files from the project.

image

After deleting files right click on solution explorer and click on Manage NuGet Package.

image

In Mange NuGet Packages windows search for KendoUIWeb. After searching once you get the package click on Install button to install all Kendo UI Web components to the project.

image

After clicking on Install, you should get Installing window as following. After successful installation close Mange NuGet Packages windows.

image

Once KendoUIWeb has been installed you will find KendoUI JS files has been added in Scripts folder and KendoUI CSS files along with images has been added to a kendo subfolder inside Content folder.

image

Once all the required files have been added to the project, next add a Web Form. To add a web Form right clicks on solution explorer and click on Add New Item. Choose Web Form from Web tab .

image

Now we need to add reference of Kendo on the Web Form. To get started with development add minimal you need to add below references on the page.

image

After adding all the references you are all set to start development using Kendo UI. Read more on Kendo UI here

Conditional statement in Kendo UI Template

While working I had a requirement to display a Total Seat of Venue in Kendo UI Mobile ListView. To display Venue Name and Number of Seats available, I created Kendo UI Template as following


<script type= "text/x-kendo-template" id="venueTemplate">
 <a href="\#toSomePage?vid=#= VenueID #" class="km-listview-link" data-role="listview-link">
 <h3>#= VenueName # </h3>
 <h5>Total Seats : <b> #=Capacity# </b> </h5>
 # }#
 </a>
 </script>

However on running the application I found that in some of the cases Capacity was retuning values as null.

image

Obviously displaying null was not a good idea. To display formatted information we can put condition in Kendo UI Template. Template can be modified with If-else statement as following


<script type= "text/x-kendo-template" id="venueTemplate">
 <a href="\#sessionsAtVenue?vid=#= VenueID #" class="km-listview-link" data-role="listview-link">

 <h3>#= VenueName # </h3>

 #if(Capacity ===null)
 {#
 <h5>Total Seats : <b> Not Available </b> </h5>

#}else{#
 <h5>Total Seats : <b> #=Capacity# </b> </h5>
 # }#
 </a>
 </script>

Now null value of capacity will get replaced by Not Available. On running output should be as following

image

We need to be bit cognizant for syntax. In below diagram you can see that line need to be executed as condition and keyword is enclosed in hash #.

image

In this way you can have if-else condition in KendoUI Template. I hope you find this post useful.

How to format DateTime type column from OData in Kendo UI Template

In this post we will look into, the way to format DateTime type columns of OData feed as string in Kendo UI Template.

For DateTime type of columns, OData returns number of seconds from January 1, 1970. Most likely you will be getting returned value as below,

image

Obviously you need to format returned date before displaying. You can format that using

kendo.toString ()

See demo of kendo.toString() on jsfiddle


StartTime: #= kendo.toString(
 new Date(
 new Date(
 parseInt(returnedTimeValue.ToTime.replace("/Date(", "").replace(")/",
 ""),
 10))),"g")#

You will get date formatted as following.

clip_image001

Explanation of code

Now let us examine that what exactly we are doing in above snippet. There are five steps being performed

  1. First replacing /Date( from returned value with empty string
  2. Next replacing )/ from returned value with empty string
  3. Parsing remaining returned value as integer
  4. Creating date using returned parsed integer
  5. Passing created date to kendo.string to format as desired.

In this way you can format a ODATA DateTime column using kendo.string. I hope you find this post useful.

Getting Started with Kendo UI Mobile : Video

Add References


    Test Application
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
                <!-- Kendo UI Scripts --><script type="text/javascript" src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js"></script>
<script type="text/javascript" src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js"></script>

Create View

</pre>
<div id="loginview" data-role="view">

<h1>This is Login View</h1>
</div>
<pre>

</pre>
<div id="detailview" data-role="view">

<h1>This is Detail View</h1>
</div>
<pre>

</pre>
<div id="settingview" data-role="view">

<h1>This is Setting View</h1>
</div>
<pre>

Initialize KendoUI

<script type="text/javascript">// <![CDATA[
        var app = new kendo.mobile.Application($(document.body),
            {
                initial: "loginview",
                layout: "defualtlayout"

            }
            );

// ]]></script>

Create Layout

</pre>
<div data-role="layout" data-id="defualtlayout">
<div data-role="header">
<div data-role="navbar"><a data-role="backbutton" data-align="left">
 Back
 </a>
 Test Application</div>
</div>
<div data-role="footer">
<div data-role="tabstrip"><a href="#loginview" data-icon="home">login</a>
 <a href="#detailview" data-icon="details">detail</a>
 <a href="#settingview" data-icon="settings">setting</a></div>
</div>
</div>
<pre>

Finally Full source code of Video is as following


    Test Application
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
                <!-- Kendo UI Scripts --><script type="text/javascript" src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js"></script>
<script type="text/javascript" src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js"></script></pre>
<div data-role="layout" data-id="defualtlayout">
<div data-role="header">
<div data-role="navbar"><a data-role="backbutton" data-align="left"> Back </a> Test Application</div>
</div>
<div data-role="footer">
<div data-role="tabstrip"><a href="#loginview" data-icon="home">login</a> <a href="#detailview" data-icon="details">detail</a> <a href="#settingview" data-icon="settings">setting</a></div>
</div>
</div>
<pre>

</pre>
<div id="loginview" data-role="view">
<h1>This is Login View</h1>
</div>
<pre>

</pre>
<div id="detailview" data-role="view">
<h1>This is Detail View</h1>
</div>
<pre>

</pre>
<div id="settingview" data-role="view">
<h1>This is Setting View</h1>
</div>
<pre>
<script>
        var app = new kendo.mobile.Application($(document.body),
            {
                initial: "loginview",
                layout: "defualtlayout"

            }
            );
</script>

Working with KendoUI Mobile Switch in Four steps

In this post we will learn how to work with KendoUI Mobile ActionSheet in four steps. You can learn more about this here

Switch is in action as following

clip_image001 clip_image002

Let us follow below steps to work with switch.

Step 1

Add all the required references to work with Kendo UI on your page .Make sure you are adding references in Head section of the page


<head>
 <title>
 Working with Switch
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>

</head>

Step 2

Next we need to create a main view on the page and initialize the page to be used as page of mobile application. For this just above closing body tag add following script

<script>
var app = new kendo.mobile.Application($(document.body), {
initial: "mainview"
});
</script>
</body>

You will notice that we have set initial view property. So let us go ahead and create a view with the id mainview

<div data-role="view" id="mainview" >

</div>

By this step we have added all the required references and created the main view to put Switch inside that.

Step 3

Now we can put a Mobile Switch as following


<div data-role="view" id="mainview" >
<input type="checkbox" data-role="switch" />
</div>

Only you need to provide value of data-role attribute as switch of checkbox element. Suppose we want to check this on click event of a button. For that let us put a button in the maindiv . On click of button we will check whether switch is on or off.

After adding button div will be as following


<div data-role="view" id="mainview" >
<input type="checkbox" data-role="switch" id="onoffswitch" />
 <a data-role="button" data-click="checkSwitchState">Check Switch State</a>
</div>

And on click of button function checkSwitchState is being called. See the data-role property of button. Now let us write checkSwitchState function.


<script>
 function checkSwitchState() {
 var switch1 = $("#onoffswitch").data("kendoMobileSwitch");
 var checked = switch1.check();
 alert(checked);
}
</script>

You can Toggle the button as following,


<script>
 function checkSwitchState() {
 var switch1 = $("#onoffswitch").data("kendoMobileSwitch");

 switch1.toggle();

}
</script>

Now let us stop for a moment and run the page to see how it works

image

image

On click event of the button, switch will be toggled and we will get alert on the state of the switch.

image

And on clicking Ok switch will be toggled.

image

Below you can find full source code of above discussions.

<!DOCTYPE html>
<html>
<head>
 <title>
 Sharing on Social Media
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>

</head>
<script>
 function checkSwitchState() {
 var switch1 = $("#onoffswitch").data("kendoMobileSwitch");
 var checked = switch1.check();
 alert(checked);
 switch1.toggle();
 }
</script>

<body>
<div data-role="view" id="mainview" >
<input type="checkbox" data-role="switch" id="onoffswitch" />
 <a data-role="button" data-click="checkSwitchState">Check Switch State</a>
</div>
<script>
 var app = new kendo.mobile.Application($(document.body), {
 initial: "mainview"
 });
</script>
</body>
</html>

Step 4

Sometime you may want to fire an event when user is changing state of the switch. You can do that as following


$("#onoffswitch").data("kendoMobileSwitch").bind("change", function (e) {
 console.log(e.checked); // true or false
 alert(e.checked);
 });

In this way we can work with Switch in KendoUI Mobile in four steps. I hope you find this post useful. Any comment is welcome.

Working with KendoUI Mobile ActionSheet in Four steps

In this post we will learn how to work with KendoUI Mobile ActionSheet in four steps. You can learn more about this here

ActionSheet in action as below,

image

Let us start creating it by following below steps.

Step 1

Add all the required references to work with Kendo UI on your page .Make sure you are adding references in Head section of the page


<head>
 <title>
 Sharing on Social Media
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>

</head>

Step 2

Next we need to create a main view on the page and initialize the page to be used as page of mobile application. For this just above closing body tag add following script


<script>
 var app = new kendo.mobile.Application($(document.body), {
 initial: "mainview"
 });
</script>
</body>

You will notice that we have set initial view property. So let us go ahead and create a view with the id mainview


<div data-role="view" id="mainview" >

</div>

By this step we have added all the required references and created the main view to put Action Sheet inside that.

Step 3

Now we will add a button. On touch of this event ActionSheet will be open. Let us add button inside the view as following


<div data-role="view" id="mainview" >
 <a data-role="button" data-rel="actionsheet" href="#shareonSocialMediaActionSheet
">Share on Social Media</a>

</div>

If you notice in button attributes we are setting

clip_image002

Step 4

Now we need to add actionsheet on the page. ActionSheet can be created by setting data-role property of <ul> as actionsheet . To create actionsheet there must be at-least one <li> inside <ul>. shareOnsocialmedia actionsheet can be created as following


<ul data-role="actionsheet" id="shareonSocialMediaActionSheet">
 <li><a data-action="functionToShareOnFacebook">Facebook</a></li>
 <li><a data-action="functionToShareOnTwitter">Twitter</a></li>
 <li><a data-action="functionToShareOnLinkedin">Linkedin</a></li>
 <li><a data-action="functionToShareOnFlickr">Flickr</a></li>
</ul>

Some points about above code is as following

  • There are links <a> inside <li>. data-action attribute of <a> is set to JavaScript function we want call on the tap of the item in actionsheet
  • After execution of the function set in data-action control will returned to calling DOM element.
  • By default a cancel item will get added to the ActionSheet.

Running Application

Let us go ahead and run the application to see ActionSheet in the action.

clip_image001

On touch of this button ActionSheet will open as following

clip_image003

You can see that Cancel item has been added by the framework itself. On tap of cancel control will return to calling DOM element.

Below you can find full source code of above discussion


<!DOCTYPE html>
<html>
<head>
 <title>
 Sharing on Social Media
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>

 <script>
 function functionToShareOnFacebook(e) {

 console.log("share on FB");
 }

function functionToShareOnTwitter(e) {
 console.log("share on Twitter");
 }
 function functionToShareOnLinkedin(e) {
 console.log("share on Linkedin");
 }

function functionToShareOnFlickr(e) {
 console.log("share on Flickr");
 }

 </script>

</head>

<body>

<div data-role="view" id="mainview" >
 <a data-role="button" data-rel="actionsheet" href="#shareonSocialMediaActionSheet">Share on Social Media</a>
<ul data-role="actionsheet" id="shareonSocialMediaActionSheet" cancel="hello" >
 <li><a data-action="functionToShareOnFacebook">Facebook</a></li>
 <li><a data-action="functionToShareOnTwitter">Twitter</a></li>
 <li><a data-action="functionToShareOnLinkedin">Linkedin</a></li>
 <li><a data-action="functionToShareOnFlickr">Flickr</a></li>
</ul>
</div>
<script>
 var app = new kendo.mobile.Application($(document.body), {
 initial: "mainview"
 });
</script>
</body>
</html>

In this way you can work with KendoUI Mobile ActionSheet in four steps. I hope you find this post useful. Thanks for reading.

Creating Netflix Movie Explorer Application using KendoUI and OData


Objective

In this post series we are going to make Netflix Movie Explorer App. We will use Kendo UI OData feed of Netflix to create application. Final application (after this post) will look like as following,

And on tapping of a movie, we will be navigated to

In order to create this application we will explore following in this post

  • Working with KendoUI Mobile ListView
  • Working with KendoUI Mobile View
  • Working with kendoUI Mobile View Layout
  • Working with Navigation between views
  • Working with creating datasource and OData.

To start with we need to add following reference on HTML page

After adding all the required references let us try to create a Mobile View. A Mobile view contains single HTML page with multiple mobile views on that. For example you can have LoginView, ShowDataView ,AboutView . All mobile views are a div element with data-role property set to view. A View can be created as following,

You can set default view of the application in Application Startup. Let us set default view of the application as LoginView. That can be set as following,

Additionally we can set layout of the mobile application as well. There are two ways we can set the layout. Either we can set on the application level or we can set on particular view level. Let us set layout on application level. This can be set as following,

We have set the layout of the application. Now we need to create application layout we set. A Layout can be created as following,

  • Create a <div> element.
  • Set data-role property as “layout”

Hence layout can be created as following,

A Layout can have a Header and Footer. We can define Header and Footer in layout as following,

Let us put a back button in the header. A back button can be put as following

image_thumb26

We have put nav bar and inside that a back button as header. A nav bar can be created as following

  • Create a <div> element.
  • Set data-role property to “navbar”

Inside the navigation bar we are putting a back button. That can be put as <a> link with setting data-role as “backbutton”

As of now we are done with navigation bar in header. Now let us create TabStrip in the footer.

image_thumb29

A TabStrip can be created as following,

  • Create a <div> element
  • Set data-role property to “tabstrip”

Inside “tabstrip” we can have buttons to navigate between the pages. We are putting three buttons to navigate. We can specify view to navigate in href property of <a>.

  • View to be navigated can be set by providing view id with hash tag as href property.
  • Data-icon can be set to provide a specific look to button.

Putting all the codes together,

<html>
 <head>
 <title>
 Test Application
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="js/jquery.min.js" type="text/javascript"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>
 </head>
 <body>
 <div data-role="view">
 <div data-role="header">Header</div>
 Hello world!
 <div data-role="footer">Footer</div>
 </div>

<div data-role="view" id="LoginView" >
 <h1>This is a Login View </h1>
 </div>
 <div data-role="view" id="DataView" >
 <h1>This is a Data View </h1>
 </div>
 <div data-role="view" id="AboutView" >
 <h1>This is a About View </h1>
 </div>
 <div data-role="layout" data-id="TestAppLayout">
 <div data-role="header">
 <div data-role="navbar">
 <a data-role="backbutton" data-align="left">
 Back
 </a>
 Test Application
 </div>
 </div>
 <div data-role="footer">
 <div data-role="tabstrip">
 <a href="#LoginView" data-icon="settings">Login</a>
 <a href="#DataView" data-icon="download">Data</a>
 <a href="#AboutView" data-icon="home">About</a>
 </div>
 </div>
 </div>

<script type="text/javascript">
 var app = new kendo.mobile.Application($(document.body), {
 initial: "LoginView",
 layout: "TestAppLayout"
 }
 );
 </script>

 </body>
</html>
</html>

Now go ahead and run the application. In mobile browser you should be getting output as following

image_thumb32

As of now we have set layout at the application level. If we want we can have different layout for different view. Let us try that by giving different layout to DataView.

Create specific layout for DataView as following,

image_thumb35

We can set layout for DataView as following,

image_thumb38

If you notice here we have set layout at application level as well as view level. When layout is set at both levels then view level layout takes precedence over application level layout. After doing above modifications we should be getting following output,

image_thumb41

On clicking of Data, you should be getting below output. If you notice Back button from header is working as expected.

image_thumb44

Now let us try to show some data from service. In this case we will be displaying Movie details from OData feed of Netflix.

You can find Title of all the Movies from Netflix ODATA from below link.

http://odata.netflix.com/Catalog/Titles

Very first we need to create DataSource reading data from ODATA feed. We can create KendoUI Datasource as following

image_thumb47

  • Instance of kendo.data.DataSource being created
  • Since data being fetched from ODATA feed so type is set to odata
  • Pagesize property is set to tell server how many records need to be fetched. In this case it is 5.
  • In Trasnport property we need to provide URL of ODATA feed.

Once we created datasource we need to create Template. In template we say how we want to show data in listview. A template can be created as following

image_thumb50

In template we set property of DOM elements with the property of datasource. For example we want to display name of the movie. We are setting that with datasource property data.Name. Here data is name of the datasource and Name is property. A very important point need to be noticed is href value of <a> DOM element. We are setting that to DataDetailView. On tap user will be navigated to this view.

As of now we have created datasource and temple. Now let us create listview. To create a listview modify data div as following,

image_thumb53

A listview can be created by setting data-role property of <ul> as listview. If you notice we are setting data-init property of view as getMovieDetails. In getMovieDetails function we are fetching data from OData feed and setting the template as following. We are setting template and datasource value in the property.

image_thumb56

Combining all the discussions together and putting all the codes together we should have following code in HTML file.

<html>
 <head>
 <title>
 Test Application
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="js/jquery.min.js" type="text/javascript"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>

 </head>
 <body>
 <div data-role="view">
 <div data-role="header">Header</div>
 Hello world!
 <div data-role="footer">Footer</div>
 </div>

<div data-role="view" id="LoginView" >
 <h1>This is a Login View </h1>
 </div>

<div data-role="view" id="DataView" data-init="getMovieDetails" >
 <ul id="movieTitleView" data-role="listview"></ul>
 </div>

 <div data-role="view" id="AboutView" >
 <h1>This is a About View </h1>
 </div>
 <div data-role="layout" data-id="TestAppLayout">
 <div data-role="header">
 <div data-role="navbar">
 <a data-role="backbutton" data-align="left">
 Back
 </a>
 Test Application
 </div>
 </div>
 <div data-role="footer">
 <div data-role="tabstrip">
 <a href="#LoginView" data-icon="settings">Login</a>
 <a href="#DataView" data-icon="download">Data</a>
 <a href="#AboutView" data-icon="home">About</a>
 </div>
 </div>
 <script type="text/javascript">
 var app = new kendo.mobile.Application($(document.body), {
 initial: "LoginView",
 layout: "TestAppLayout"

 }
 );
 </script>
<script id="movieTemplate" type="text/x-kendo-template">
 <div>
 <img src=${data.BoxArt.MediumUrl} height="50" width="50" />
 <strong>${data.Name}</strong>
 <a href="\#DataDetailView?Id=#:data.Id#"" data-role="detailbutton" data-style="detaildisclose"></a>
 </div>
 </script>
<script>
 var data;
 data = new kendo.data.DataSource(
 {
 type: "odata",
 pageSize: 5,
 endlessScroll: true,
 scrollTreshold: 30,
 transport:{
 read: {
 url: "http://odata.netflix.com/Catalog/Titles",
 dataType: "jsonp",

data: {
 Accept: "application/json"
 }
 }
 }

 });
 var getMovieDetails = function () {
 $("#movieTitleView").kendoMobileListView(
 {
 template: kendo.template($("#movieTemplate").html()),
 endlessScroll: true,
 scrollTreshold: 30,
 dataSource: data
 });
 };
</script>

 </body>
</html>

On running we should be getting output as following

image_thumb59

On tap of Data button we should get below output

image_thumb62

At this point of time of you tap on the detail button you will be getting an exception because we have not created detail view yet. Let us create detail view

image_thumb65

Here we are setting different layout to DataDetailView. Let us create layout as below,

image_thumb68

This layout structure is same as we discussed previously. Now we need to write function shwDeatilsView function. In this function we will fetch selected data from the server on basis of Movie selected in first view.

image_thumb71

This function is quiet simple. First we are reading query parameter as following,

image_thumb74

After that we are making a call to server to fetch specific detail of the movie. Server call is as following. We are setting filter to fetch specific record.

image_thumb77

Once data is being fetched from the server, we need to initialize downloaded data to Movie Detail template. This template will tell how we are going to show data in movie detail page.

image_thumb80

We need to write MovieDetailtemplate as following,

image_thumb84

Combining all the discussions together and putting all the codes together we should have following code in HTML file.


<html>
 <head>
 <title>
 Test Application
 </title>
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.common.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.default.min.css" rel="stylesheet" />
 <link href="http://cdn.kendostatic.com/2012.1.515/styles/kendo.mobile.all.min.css" rel="stylesheet" />
 <script src="js/jquery.min.js" type="text/javascript"></script>
 <!-- Kendo UI Scripts -->
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js" type="text/javascript"></script>
 <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.mobile.min.js" type="text/javascript"></script>

 </head>
 <body>
 <div data-role="view">
 <div data-role="header">Header</div>
 Hello world!
 <div data-role="footer">Footer</div>
 </div>

<div data-role="view" id="LoginView" >
 <h1>This is a Login View </h1>
 </div>

<div data-role="view" id="DataView" data-init="getMovieDetails" >
 <ul id="movieTitleView" data-role="listview"></ul>
 </div>

 <div data-role="view" id="AboutView" >
 <h1>This is a About View </h1>
 </div>
 <div data-role="layout" data-id="TestAppLayout">
 <div data-role="header">
 <div data-role="navbar">
 <a data-role="backbutton" data-align="left">
 Back
 </a>
 Test Application
 </div>
 </div>
 <div data-role="footer">
 <div data-role="tabstrip">
 <a href="#LoginView" data-icon="settings">Login</a>
 <a href="#DataView" data-icon="download">Data</a>
 <a href="#AboutView" data-icon="home">About</a>
 </div>
 </div>
 </div>
 <div data-role="layout" data-id="TestAppDataLayout">
 <div data-role="header">
 <div data-role="navbar">
 <a data-role="backbutton" data-align="left">
 Back
 </a>
 Data
 </div>
 </div>
 <div data-role="footer">
 <div data-role="tabstrip">
 <a href="#DataView" data-icon="download">Save</a>
 </div>
 </div>
 </div>
 <div data-role="view" id="DataDetailView"
 data-layout="TestAppDataLayout"
 data-show="showDetailsView">
 <h1>This is a Data Detail View </h1>
 </div>

<script type="text/javascript">
 var app = new kendo.mobile.Application($(document.body), {
 initial: "LoginView",
 layout: "TestAppLayout"

 }
 );
 </script>

<script id="movieTemplate" type="text/x-kendo-template">
 <div>
 <img src=${data.BoxArt.MediumUrl} height="50" width="50" />
 <strong>${data.Name}</strong>
 <a href="\#DataDetailView?Id=#:data.Id#"" data-role="detailbutton" data-style="detaildisclose"></a>
 </div>
 </script>

<script id="movieDetailTemplate" type="text/x-kendo-template">
 <div>
 <img src=${data.BoxArt.MediumUrl} height="100" width="100"/>
 <br/>
 Movie Name : <strong>${data.Name}</strong>
 <br/>
 ${data.Synopsis}
 </div>
 </script>
 <script>
 var data;
 data = new kendo.data.DataSource(
 {
 type: "odata",
 pageSize: 5,
 endlessScroll: true,
 scrollTreshold: 30,

 transport:{
 read: {
 url: "http://odata.netflix.com/Catalog/Titles",
 dataType: "jsonp",

data: {
 Accept: "application/json"
 }
 }
 }

});

console.log(data);

 var getMovieDetails = function () {

$("#movieTitleView").kendoMobileListView(
 {
 template: kendo.template($("#movieTemplate").html()),
 endlessScroll: true,
 scrollTreshold: 30,
 dataSource: data
 });
 };
 var movieDetailTemplate = kendo.template($("#movieDetailTemplate").text());

function showDetailsView(e) {
 var view = e.view;
 console.log(view.params.Id);
 var query = view.params.Id.toString();
 var data1 = new kendo.data.DataSource(
 {
 type: "odata",
 serverPaging: true,
 serverFiltering: true,
 pageSize: 50,
 transport: {

 read: "http://odata.netflix.com/Catalog/Titles"
 },

filter: { filters: [{ field: "Id", operator: "eq", value: query}] }
 });
 data1.read();
 data1.fetch(function () {
 var item = data1.at(0);
 console.log(item);
 view.scrollerContent.html(movieDetailTemplate(item));
 kendo.mobile.init(view.content);
 });
 }

</script>

 </body>
</html>

Now let us go ahead and run application

image_thumb87

Now when we select a movie, we will go into detail of that movie

image_thumb90

Conclusion

Yes detail view is not that immersive. In second part of this post, we will make it more immersive and implement much more features. I hope you like this post. Thanks for reading.