This is a migrated thread and some comments may be shown as answers.

PullParameters function along with Pull To Refresh

4 Answers 99 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Yohann
Top achievements
Rank 1
Yohann asked on 23 Feb 2014, 02:18 AM
Hello,

I'm trying to have my ListView working with Pull To Refresh. Nevertheless, I can't have the listview refresehd.

basically, when a user trigger pull to refresh, it should replace the whole content of the list view.

Here is how I have handled my list view and the pull to refresh:


$.when( Event.getEventsNearby( position.coords.latitude, position.coords.longitude, radius, limit, offset, key ) ).done(
function( response )
    {
        var dataToBeCached = new Array();
 
        //In order not to cache the same results twice
        var previousContent;
 
        if( response.containsResults )
        {
            var results = response.results;
            //On chope le nombre de resultats. Si !=limit, il y a de grandes chances qu'il n'y ai plus de resultats par la suite.
            // resultLength = data.length;
 
            // //On progresse dans les resultats
            // //Et on adapte offset et limit
            // offset += resultLength;
            // limit = offset + 20 ;
 
            //Merge the previous content with the new one
            // previousContent = JSON.parse( getItem("contentEvent") );
            // if ( previousContent != null )
            // {
            //  var dataToBeCached = dataToBeCached.concat(previousContent);
            // };
 
            //Remove previous markers
            Map.clearMarkers();
 
            // Add Markers on the map
            Map.setMarkerPosition( position.coords.latitude, position.coords.longitude, "grey" );
            for ( var i=0; i<results.length; i++ )
            {
                Map.setMarkerPosition( results[i].lat, results[i].lng, "green");
                results[i]["index"] = i;
            }
 
            setItem("events", JSON.stringify( results ), 1);
 
            var template = Handlebars.compile( $( '#eventListTemplate' ).html() );
            $("#list-container").kendoMobileListView({
                template : template,
                dataSource: kendo.data.DataSource.create(results),
                fixedHeaders: false,
                pullToRefresh: true,
                pullParameters: function(item) {
                    console.log("pull");
                    //Here, another AJAX call to get the new results
                    $.when( Event.getEventsNearby( position.coords.latitude, position.coords.longitude, radius, limit, offset, key ) ).done( function( response )
                    {
                        console.log("when");
                        //I can see I'm getting my results properly here.
                        console.log(response.results);
                        //Doesn't work ...
                        return response.results;
                    });
                }
            });
 
            //We remove those fucking classes added by default with Kendo UI
            // $("#list-container").removeClass("km-widget km-listview km-list");
            // $(".post-actions [data-role='button']").removeClass("km-widget km-button");
 
            $( document ).trigger( "wallReady" );
 
            //Retrieve the different user conversations:
            updateListOfChats();
 
        }
});


What should I put into the pullParameters function to make it work ? Thanks.

4 Answers, 1 is accepted

Sort by
0
Yohann
Top achievements
Rank 1
answered on 23 Feb 2014, 02:26 AM
I'm posting the code again without the unnecessary comments for clarity purpose. (How do we edit posts ?)

function handle_geolocation_query( position )
{
    $.when( Event.getEventsNearby( position.coords.latitude, position.coords.longitude, radius, limit, offset, key ) ).done( function( response )
    {
        var dataToBeCached = new Array();
 
        //In order not to cache the same results twice
        var previousContent;
 
        if( response.containsResults )
        {
            var results = response.results;
             
            //Remove previous markers
            Map.clearMarkers();
 
            // Add Markers on the map
            Map.setMarkerPosition( position.coords.latitude, position.coords.longitude, "grey" );
            for ( var i=0; i<results.length; i++ )
            {
                Map.setMarkerPosition( results[i].lat, results[i].lng, "green");
                results[i]["index"] = i;
            }
 
            setItem("events", JSON.stringify( results ), 1);
 
            var template = Handlebars.compile( $( '#eventListTemplate' ).html() );
            $("#list-container").kendoMobileListView({
                template : template,
                dataSource: kendo.data.DataSource.create(results),
                fixedHeaders: false,
                pullToRefresh: true,
                pullParameters: function(item) {
                    console.log("pull");
                    //Here, another AJAX call to get the new results
                    $.when( Event.getEventsNearby( position.coords.latitude, position.coords.longitude, radius, limit, offset, key ) ).done( function( response )
                    {
                        console.log("when");
                        //I can see I'm getting my results properly here.
                        console.log(response.results);
                        //Doesn't work ...
                        return response.results;
                    });
                }
            });
 
            $( document ).trigger( "wallReady" );
 
            //Retrieve the different user conversations:
            updateListOfChats();
        }
    } );
};
0
Petyo
Telerik team
answered on 25 Feb 2014, 12:06 PM
Hello Yohann,

I think that you have asked the same question in StackOverflow - please check my response there.

Regards,
Petyo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Yohann
Top achievements
Rank 1
answered on 26 Feb 2014, 11:29 PM
yes.

Thanks for your answer. I've commented your answer :)
0
Petyo
Telerik team
answered on 28 Feb 2014, 04:19 PM
Hello Yohann,

Like I replied in stack overflow, the pull parameters function should return the parameters about to be passed in the next request, which is performed by the datasource component itself. 

In your case, instead of returning query parameters object, you perform a request. Returning the result in the ajax promise callback does not help much. This is a return statement in the promise callback itself - it won't unwind to a return statement of the pullParameters function itself. 

I hope that my explanations are clear. In case you have missed it, please refer to the code sample I linked.

Regards,
Petyo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView (Mobile)
Asked by
Yohann
Top achievements
Rank 1
Answers by
Yohann
Top achievements
Rank 1
Petyo
Telerik team
Share this question
or