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

How to Use pullParameters

3 Answers 33 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kelly
Top achievements
Rank 1
Kelly asked on 26 Feb 2014, 10:55 PM
Hello,

I'm using endless scrolling and pull-to-refresh in a list view.  My DataSource contains a server-side sort on CreatedAt in descending order.  Since newer records can NEVER have a CreatedAt with a value greater than a record created earlier in time, my listview is finite at the bottom, but infinite at the top.  In other words, I need endless scrolling at the top of the listview, since new records will be sorted to the top of the list.

It sounds like the pull-to-refresh feature is what I need to find these new records.  I'm having trouble getting it work, though, and need some advice.

I've gotten as far as getting my pullParameters function to be called, passing the data item that is currently at the top of the listview.  I don't understand what I need to return in order for the refresh of the DataSource to occur.  Here is how my data source is defined:

var dataSource = new kendo.data.DataSource({
    type: 'everlive',
    transport: {
        typeName: 'Test'
    },           
    pageSize: 20,
    serverPaging: true,
    serverSorting: true,           
    sort: [
        { field: 'CreatedAt', dir: 'desc' }
    ],
    change: function(e) {
        var data = this.data();
        console.log('First: ' + data[0].Text + '  Last: ' + data[data.length - 1].Text);
    }          
});

I've watched the Logs, and see that the pull-to-refresh callback is just repeating the last query made before the pull.  For example, if I have scrolled to the bottom of the list of 100 records, it sends skip: 100 take: 20.  All I want to do is have the pullParameters reset the skip to 0.

The pullParameters documentation says "The result of the function will be send as additional parameters to the DataSource's next method."  I don't even see a "next" method in the DataSource doc.  I don't see any point to sending "additional parameters" to Everlive for a straight query, and I checked the logs and don't see any parameters sent when I do return something from pullParameters.  So instead of returning anything, I just add the following to my pullParameters function:

pullParameters: function (e) {
   this.dataSource.page(1);
}

1)  Now, I'm getting the result I want, but I don't think I'm doing it correctly and I'm afraid it will break.  So, please - what do I need to return in pullParameters to reset the datasource to the top?

2) Also, is it possible to define pullParameters in the markup?  I've tried data-pull-parameters, data-pullparameters, etc and can't get it to fire unless I call kendoMobileListView() directly.

Thank you,

Kelly

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 03 Mar 2014, 04:06 PM
Hi Kelly,

the pullParameters function should return a key/value object, which will be available as additional parameters in the request performed by the datasource. Please check the API reference for a working example. 

Unfortunately, pull parameters can't be assigned with a data attribute since it is a bit different from the other configuration options (it is a function). 

Regards,
Petyo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kelly
Top achievements
Rank 1
answered on 03 Mar 2014, 04:17 PM
Thanks Petyo - I've read the API reference a hundred times (I quoted it in my query) - it doesn't answer my question.  There is no code on the server looking for additional parameters other than Everlive.  What key/value object would I send to Everlive that would set the Skip value to 0?

As I noted, setting the Page to 1 in my DataSource is working fine.  I'm perfectly happy to leave it as is.  I haven't seen any bad effects from doing it that way, and if I ever do, I'll ask again.

Sincere thanks, Kelly
0
Petyo
Telerik team
answered on 06 Mar 2014, 09:07 AM
Hi Kelly,

if I understand you correctly, you don't have to deal with pullParameters at all - by default, when pull to refresh is executed, the datasource will request the first page and update the ListVIew accordingly. You can check how this works in the following demo. I scrolled down a bit (the second page was requested), then scrolled back, and the third request was performed, using skip=0 – see attached screenshot. 

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