ListView / Press to load more

kendoui mobile demo ListView / Press to load more

by jmucci

HTML

<script src="http://cdn.kendostatic.com/2012.3.1114/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.mobile.all.min.css">
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <div data-role="view" data-init="mobileListViewPressToLoadMore" data-title="Twitter">
    <header data-role="header">
        <div data-role="navbar">
            <span data-role="view-title"></span>
            <a data-align="right" data-role="button" class="nav-button" href="#index">Index</a>
        </div>
    </header>

    <ul id="load-more"></ul>
</div>

<script id="load-more-template" type="text/x-kendo-template">
    <div class="tweet">
        <img class="pullImage" src="#= profile_image_url #" alt="#= from_user #" />#= text #
        <div class="metadata">
            <a class="sublink" target="_blank" href="http://twitter.com/\\#!/#= from_user #/status/#= id_str #" rel="nofollow">#= kendo.toString(new Date(Date.parse(created_at)), "dd MMM HH:mm") #</a>
            |
            <a class="sublink" href="http://twitter.com/#= from_user #" rel="nofollow">#= from_user #</a>
        </div>
    </div>
</script>

CSS

.tweet {
        font-size: .8em;
        line-height: 1.4em;
    }
    .pullImage {
        width: 64px;
        height: 64px;
        border-radius: 3px;
        float: left;
        margin-right: 10px;
    }
    .sublink {
        font-size: .9em;
        font-weight: normal;
        display: inline-block;
        padding: 3px 3px 0 0;
        text-decoration: none;
        opacity: .8;
    }

JavaScript

function mobileListViewPressToLoadMore() {
            var dataSource = new kendo.data.DataSource({
                pageSize: 3,
                serverPaging: true,
                transport: {
                    read: {
                        url: "http://search.twitter.com/search.json", // the remove service url
                        dataType: "jsonp" // JSONP (JSON with padding) is required for cross-domain AJAX
                    },
                    parameterMap: function(options) {
                        var parameters = {
                            q: "javascript", //additional parameters sent to the remote service
                            rpp: options.pageSize,
                            page: options.page //next page
                        };

                        return parameters;
                    }
                },
                schema: { // describe the result format
                    data: "results" // the data which the data source will be bound to is in the "results" field
                }
            });

        $("#load-more").kendoMobileListView({
            dataSource: dataSource,
            template: $("#load-more-template").text(),
            loadMore: true
        });
    }


var app = new kendo.mobile.Application(document.body);