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

Manually display data from a DataSource that uses remote data?

2 Answers 106 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 29 Mar 2013, 03:17 PM
I have a ListView and Pager bound to a DataSource that gets its data from a remote url (i.e. using transport.read).  For the sake of this example we'll call the objects returned by the url and bound to the DataSource, "DataSourceObjects".  It works as expected.  

However, the ListView exists on a webpage that uses ajax to update other elements on the webpage (Call #1).  When those other elements update, the ListView must update and display data from a different page of the DataSource, based on the new values of those elements.  This means a call to DataSource.page() and thus another round-trip to the server (Call #2).  I'd like to combine Call #1 and Call #2 into one call.  I should be able to do this by sending the DataSourceObjects for the new page during Call#1 and then manually updating the DataSource with those new DataSourceObjects, bypassing the DataSource.page() call and bypassing transport.read().  I'd also need to manually update the page being displayed by the Pager attached to the DataSource, again without it making another call to the server.

I've done a lot of looking around to see how this could be accomplished but haven't found an example of what I'm describing.  I've gotten so far as to update the data being displayed by the ListView by calling DataSource.data(DataSourceObjects), but I can't get the Pager to display the right page number.  I read a suggestion to try DataSource.query({ page: NewPageNumber }) but that doesn't seem to work.

Can you tell me how to accomplish what I've described?  Thanks.


UPDATE:
I was able to use the get the .query() call working as described here (http://www.kendoui.com/forums/framework/data-source/setiing-pagesize-dynamically-causing-read-.aspx).  Calling manuallyUpdateDataSource() seems to update the data as I want it to, but the .query() line causes a server hit, which I don't want.
var myDataSource = new kendo.data.DataSource({
            pageSize: 10,
            serverPaging: true,
            transport: {
                read: {
                    url: 'http://mydataurl/',
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest'  
                    }
                },
                parameterMap: function (data, type) {
                     // Code for parameterMap.
                }
            },
            schema: {
                data: 'Data',
                total: 'Total'
            },
        });
 
function manuallyUpdateDataSource(dataSourceObjects) {
     myDataSource.data(dataSourceObjects);
     myDataSource.query({ pageSize: 10, page: 3 });   // setting to page 3 just for testing.
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 02 Apr 2013, 11:24 AM
Hi Don,

I am afraid that what you would like to achieve is not supported by the DataSource out of the box. If serverPaging is enabled, the DataSource will perform ajax request to the server every time page is changed. It does not matter if query or page method is used.

If I understood correctly Call #1 and Call #2 returns the same data set (dataSourceObjects) which is the reason you want to combine them. Then probably you may consider the opposite scenario - update the DataSource page (respectively the ListView and Pager bound to it), get the updated dataSource's data and modify other elements on the web page.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Don
Top achievements
Rank 1
answered on 04 Apr 2013, 04:53 PM
"If I understood correctly Call #1 and Call #2 returns the same data set (dataSourceObjects) ..."

Actually, no.  Call #1 primarily returns other data and is triggered by calls from the comet server.  What I was saying was that it could also return dataSourceObjects that could be used to populate the DataSource, manually.  But, as you said, what I'm trying to accomplish can't be done out of the box.  Thanks for the response.

Tags
Data Source
Asked by
Don
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Don
Top achievements
Rank 1
Share this question
or