Home Mobile Instant Kendo UI Mobile

Instant Kendo UI Mobile

By Sagar Ganatra
books-svg-icon Book
Subscription FREE
eBook + Subscription €14.99
eBook €15.99
Print + eBook €19.99
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
Subscription FREE
eBook + Subscription €14.99
eBook €15.99
Print + eBook €19.99
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
About this book
The Kendo UI Mobile library is a one stop solution to build mobile applications rapidly. It comes with several built-in widgets that enable application developers to build intuitive applications for small screen devices. It also provides more control to these developers by providing various components that can be extended or configured to match their needs. Instant Kendo UI Mobile How-to takes a deep look at various components of the Kendo UI Mobile library and provides solutions to common use cases involved in building a mobile application. It enables application developers to use HTML, CSS, and JavaScript to build mobile applications that provide a native look and feel on various platforms such as iOS, Android, and BlackBerry without having to maintain a separate code base. This guide introduces the user to the Kendo UI Mobile library and provides a step-by-step approach to creating your first mobile application. It then introduces you to several components and provides solutions to some of the common use cases you may encounter in your development. The Kendo UI Mobile library is composed of two parts – the aplication framework and a set of widgets. The aplication framework focuses on configuring the application, handling various touch-based events, rendering on different devices to provide a native look and feel, and transitioning from one view to the other. The widget library contains several widgets that enable you to build applications more rapidly than ever before.
Publication date:
July 2013
Publisher
Packt
Pages
60
ISBN
9781849699112

 

Chapter 1. Instant Kendo UI Mobile

Welcome to Kendo UI Mobile. This book will tell you how to get started with the Kendo UI Mobile framework and also build a sample application using this framework.

 

Downloading Kendo UI Mobile (Simple)


The Kendo UI Mobile library comes with several widgets and a framework that aids you in building mobile applications quickly. Firstly, you need to download the framework and then include the necessary files in your HTML page.

Getting ready

To download the Kendo UI Mobile framework, navigate to www.kendoui.com and click on the Download button. You will be provided with the following five options on the download page:

  • Kendo UI WEB: It is an open source version that includes components for building applications for the Web. Please note that this does not include the mobile library.

  • Kendo UI Complete for PHP: A 30-day free trial version of Kendo UI Web, mobile, data-visualization libraries, and server wrappers for PHP.

  • Kendo UI Complete for JSP: A 30-day free trial version of Kendo UI Web, mobile, data-visualization libraries, and server wrappers for JSP.

  • Kendo UI Complete for ASP.NET MVC: A 30-day free trial version of Kendo UI Web, mobile, data-visualization libraries, and server wrappers for ASP.NET MVC.

  • Kendo UI Complete: A 30-day free trial version of Kendo UI Web, mobile, and data-visualization libraries.

How to do it...

It is recommended that you download the free trial version of Kendo UI Complete (the last option in the previous list). However, if you prefer any of the server-side programming languages mentioned previously to generate the client-side JavaScript code, you can download the respective option. Now, perform the following steps:

  1. Click on the Download Free Trial button under Kendo UI Complete.

  2. You will be required to sign up before downloading the trial version.

  3. Once you have signed up, the download page will be shown and an automatic download of files will start immediately.

  4. The downloaded ZIP archive will contain the following directories:

    • /examples: A set of examples for the Kendo UI Web, mobile, and data visualization

    • /js: A set of minified JavaScript files

    • /css or /styles: A set of minified CSS files

    • /vsdoc: The completion helper for Visual Studio 2008 SP1 or newer

    • /license-agreements: This contains the license agreement documents

    • Changelog.html: This contains the release notes

    • README: This contains the readme document

You can run the applications that have been built using this library, which can be found in the examples directory. In the next recipe, we will see how you can build a sample application using the Kendo UI Mobile library.

 

Creating a sample application (Simple)


A Kendo Mobile application is built using HTML5, CSS, and JavaScript. The framework provides JavaScript and CSS files that should be included in your project. A Kendo mobile application can be viewed as being made up of two pieces – the framework and a set of widgets. The framework provides core functionality such as loading views, managing application history, and navigation. The widgets allow you to add visual elements to the page and Kendo UI Mobile comes with several of them that aid you in building the application.

How to do it...

To create an application, include the JavaScript and CSS files in your page. Perform the following steps:

  1. Create an HTML document, index.html, under your project directory. Please note that this directory should be placed in the web root of your web server.

  2. Create the directories styles and scripts under your project directory.

  3. Copy the CSS file kendo.mobile.all.min.css, from <downloaded directory>/styles to the styles directory created in step 2. Then add a reference to the CSS file in the head section of the document.

  4. Download the jQuery library from jQuery.com. Place this file in the scripts directory and add a reference to this file in the document before closing the body tag. You can also specify the CDN location of the file in the document.

  5. Copy the JavaScript file kendo.mobile.min.js, from the <downloaded directory>/js tag to the scripts directory created in step 2. Then add a reference to this JavaScript file in the document (after jQuery).

  6. Add the text "Hello Kendo!!" in the body tag of the index.html file as follows:

    <!DOCTYPE HTML>
    <html>
    
      <head>
        <title>My first Kendo Mobile Application</title>
        <link	rel="stylesheet"
        type="text/css"
        href="styles/kendo.mobile.all.min.css">
      </head>
    
      <body>
        Hello Kendo!!
    
        <script type="text/javascript"
        src="scripts/jquery.min.js">
        </script>
        <script type="text/javascript"
        src="scripts/kendo.mobile.min.js">
        </script>
      </body>
    
    </html>

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

The preceding code snippet is a simple HTML page with references to Kendo Mobile CSS and JavaScript files. These files are minified and contain all the features, themes, and widgets. In production, you would like to include only those that are required. The downloaded ZIP file includes CSS and JavaScript files for specific features. However, in development you can use the minified files that contain all features.

Tip

Another thing to note is that apart from the reference to the script kendo.mobile.min.js, the page also includes a reference to jQuery. It is the only external dependency for Kendo UI.

When you view this page on a mobile device, you will see the text Hello Kendo!! shown. This page does not include any of the widgets that come as a part of the library. Now let's build on top of our Hello World application and add some visual elements; that is, UI widgets to the page. This can be done with the following steps:

  1. Add a layout first. A mobile application generally has a header, a footer, and multiple views. It is also observed that while navigating through different views in an application, the header and footer remain constant. The framework allows you to define a global layout that may contain a header and a footer for all the views in the application. Also, the framework allows you to define multiple views that can share the same layout. The following is the same page that now includes a header and footer defined in the layout:

    <body>
    
    <div
      data-role="layout"
      data-id="defaultLayout">
    
      <header data-role="header">
    
        <div data-role="navbar">
          My first application
        </div>
    
      </header>
      <footer data-role="footer">
    
        <div data-role="tabstrip">
          <a data-icon="about">About</a>
          <a	data-icon="settings">Settings</a>
         </div>
    
      </footer>
    
    </div>
    
    </body>
  2. The body contains a few div tags with data attributes. Let's look into one of these tags in detail.

    <div data-role="layout" data-id="defaultLayout">

    Here, the div tag contains two data attributes, role and id. The role data attribute is used to initialize and configure a widget. The data-role attribute has a value, layout, identifying the target element as a layout widget. All the widgets are expected to have a role data attribute that helps in marking the target element for a specific purpose. It instructs the library which widget needs to be added to the page. The id data attribute is used to identify the widget (the layout widget) in the page. A page may define several layout widgets and each one of these must be identified by a unique ID. Here, the data-id attribute has defaultLayout as its value. Now there can be many views referring to this layout by its id (views are explained in the next recipe and in detail in the later ones).

  3. Similarly, there are other elements in the page with the data-role attribute, defining them as one of widgets in the page. Let's take a look at the header and footer widgets defined inside the layout.

    <header data-role="header">... </header>
    <footer data-role="footer">...</footer>

    The header and footer tags have the role data attribute set to header and footer respectively. This aligns them to the top and bottom of the page, giving the rest of the available space for different views to render. Also, note that there is a navbar widget in the header and a tabstrip widget defined in the footer. As mentioned earlier, the framework comes with several widgets that can help you build the application rapidly. The usage of navbar, tabStrip, and many other widgets will be covered in the later recipes of this book.

  4. Now add views to the page. The index.html page now has a layout defined and when you run the page in the browser, you will see an error message in the console which says:

    Uncaught Error: Your kendo mobile application element does not contain any direct child elements with data-role="view" attribute set. Make sure that you instantiate the mobile application using the correct container.

    Views represent the actual content that has to be displayed between the header and the footer that we defined while creating a layout. A layout cannot exist without a view and hence you see that error message in the console. To fix this error, you need to define a view for your mobile application.

  5. Add the following to your index.html page:

    <div data-role="view"
      data-layout="defaultLayout">
      Hello Kendo!!
    </div>

    As mentioned earlier, every widget needs to have a role data attribute to identify itself as a particular widget in the page. Here, the target element is defined as a view widget and tied to the layout by defining the data-layout attribute. The data-layout attribute has a value defaultLayout that is the same as the value for the data-id attribute of the layout that we defined earlier. This attaches the view to the layout and you will not see the error message anymore.

    Similarly, you can have multiple Views defined in the page that can make use of the same layout (we will see this in the later part of this book). Now, there's only one pending task for the application to start working: initializing the application. A Kendo Mobile application can be initialized using the Application object. To do that, add the following code to the page:

    <script>
      var app = new kendo.mobile.Application();
    </script>

    Include the previous script block right after references to jQuery and Kendo Mobile and before closing the body tag. This single line of JavaScript code will initialize your Kendo Mobile application and all the widgets with the data-role attribute.

The Application object is used for many other purposes and those will be covered in the upcoming recipes.

How it works...

When you run the index.html page in a browser, you will see a navbar and a tabstrip in the header and footer of the page. Also, the message Hello Kendo!! being shown in the body of the page. The following screenshot shows how it will look like when you view the page on an iPhone:

If you have noticed, this looks like a native iOS application. The framework has the capability to render the application that looks like a native application on a device. When you view the same page on an Android device, it will look like an native Android application, as shown in the following screenshot:

The framework identifies the platform on which the mobile application is being run and then provides native look and feel to the application. There are ways in which you can customize this behavior and this will be covered in the upcoming recipes.

In the next series of recipes, you will learn about the following core components of framework:

  • Application

  • Touch events

  • Views

  • Forms

                     
About the Author
  • Sagar Ganatra

    Sagar Ganatra is a frontend engineer and an architect from Bangalore, India. He has more than a decade of experience in developing web and mobile applications. He specializes in architecting projects using JavaScript and frameworks such as React, Angular, and Node. His previous books include Kendo UI Cookbook and Instant Kendo UI Mobile, both published by Packt Publishing. He also writes about frontend technologies in his blog, sagarganatra (dot) com.

    Browse publications by this author
Instant Kendo UI Mobile
Unlock this book and the full library FREE for 7 days
Start now