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

Remote Virtualization of Data

9 Answers 306 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 13 Sep 2011, 08:41 AM
Hi guys,

I seem to be having an issue with virtualizing data for my grid. I've initialized it with the following:

    $("#myGrid").kendoGrid({
        dataSource: {
            type: "json",
            serverPaging: true,
            serverSorting: true,
            pageSize: 32,
            transport: { read: "/Query/GetAddresses" }
        },
        height: 300,
        scrollable: { virtual: true },
        columns: cs /* The columns data stored in the cs variable */
    });

The grid initializes fine, and populates with 32 records (shows about 10 with a scrollbar due to height constraint). When i scroll down, i can see that the next ajax call is made and returns the correct json data for take=32 & skip=32 & page=2 & pageSize=32 using FireBug. The problem is that at this point, the data isn't appended to the grid. Also, any further scrolling on the scrollbar calls for page 2 again with the same parameters.

I've tried a few variations of parameters as i thought they may be intefering with each other, but couldn't get the data to come through. Any help or ideas of things to try would be appreciated.

Regards,
Tony

9 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 13 Sep 2011, 12:22 PM
Hi Tony,

 Could you please send us a small sample in which this behavior can be observed locally.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tony
Top achievements
Rank 1
answered on 14 Sep 2011, 04:36 AM
no worries.

I've set up a test page that exhibits the behaviour here:

http://www.moveware.com.au/kendo.html

Specifically:

$(document).ready(function() {
    $("#TestingAddresses_0").kendoGrid({
        dataSource: {
            type: "json",
            serverPaging: true,
            serverSorting: true,
            pageSize: 32,
            transport: {
                read: {
                    url: "<WebServiceAddress>",
                    dataType: "jsonp"
                }
            }
        },
        height: 320,
        width: 500,
        scrollable: { virtual: true },
        selectable: "row",
        sortable: false,
        pageable: false,
        columns: [{"field":"TID","title":"ID"},{"field":"T3","title":"Place"},{"field":"T5","title":"Country"}]
    });
});

However, possibly because of the cross domain call this page isn't initially being loaded with data. But you can see that the query is being made, the response json data is coming back, and nothing happens after that. No visible javascript errors either, but i assume that an onerror event is firing somewhere.

What am i missing here?

Regards,
Tony
0
Rosen
Telerik team
answered on 14 Sep 2011, 07:57 AM
Hi Tony,

I suspect that in the sample data is not loaded due to incorrect format of the result. As you are using JSONP the result should be a javascript function instead of the actual data. For example you may take a look at this JSONP call url.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tony
Top achievements
Rank 1
answered on 15 Sep 2011, 05:01 AM
Thanks for your help in pointing that out - The data is now populating again, and correctly repopulating as the scrollbar is used. I do still have one small problem though.

While completing this virtualization of data, i found that unless a total count was specified in the schema of the response, the virtual scrolling would fail to work correctly. I have some extremely large datasets to work with in certain queries that are quite complex, so providing the total count is not really an option. I tried modifying the total count on each subsequent query for a new page to be a greater value i.e. the skip count plus twice the take count (skip + 2*take). Unfortunately the grid doesn't seem to take any notice of the total count figure on subsequent page requests.

After a little fustration i added the following line of code into kendo.data.js to make the success of a subsequent page request respect the new total passed with the jsonp response data:

1779.    data = that.reader.parse(data);
1780.    that._total = that.reader.total(data);
1781.    range.data = that.reader.data(data);
1782.    range.end = range.start + range.data.length;

You can see what's happening here:

http://www.moveware.com.au/kendo.html

And this one shows the fix:

http://www.moveware.com.au/kendo-fix.html

If there is another way to fix this let me know, as obviously my change will be lost as soon as your controls are updated.

Regards,
Tony
0
Rosen
Telerik team
answered on 16 Sep 2011, 09:13 AM
Hi Tony,

I'm afraid that providing a valid total count is essential in order virtual scrolling to work correctly.
The line you have mentioned is in a function which is not directly related to the population of the grid as its purpose is to prefetch data not to rebind the grid component.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tony
Top achievements
Rank 1
answered on 19 Sep 2011, 06:55 AM
Hi Rosen,

Yes, the total count that i'm referring to is in the Kendo datasource control and not the grid control. However i've noticed that the grid respects this total count, even when it is updated dynamically on subsequent requests for more data. I can't afford the time and performance hit to run a count on my query at the start of the request, so as more data is requested by the Kendo datasource object, i send back an updated total count variable. But this total count is only updated in the Kendo datasource on the first request, not on subsequent requests for more data, which is why i added the line of code to update the total on each subsequent request (This field was being effectively ignored after the first request had been made).

So what you're telling me is that if i have a query that when run may return 200 results or may return 2,000,000 results, and i only want a page of 50 records, i still need to effectively run a scan of my query on the first request to get the correct count of my result set?

Regards,
Tony
0
Accepted
Rosen
Telerik team
answered on 19 Sep 2011, 09:48 AM
Hello Tony,

As I have mentioned in my previous post current implementation of the virtual scrolling does require total number of records to be known upfront. You may have noticed that with the suggested change the scrollbar does not behave as intended i.e. in order more records to be shown user should scroll to the bottom as opposite to the original behavior where one could scroll to arbitrary page. 

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 07 Jan 2013, 03:57 PM
Hi,

Is this still the case as we have a good number of queries that are huge and we'll need to show them in a grid without trying to count them first?
0
Atanas Korchev
Telerik team
answered on 08 Jan 2013, 08:19 AM
Hi Chris,

 Yes, this is still the case. The grid needs to know the total number of records it is going to display. 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Tony
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Tony
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or