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

Setting total with datasource schema to make paging work in grid

2 Answers 626 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Douglas
Top achievements
Rank 1
Douglas asked on 11 Mar 2014, 10:31 AM
Hi,

I'm trying to make paging work on the server side for large numbers of records. If I set schema.total to an arbitrary hard coded number then i start to see paging as expected. However I would like to return the total number of records by way of an additional angularjs rest call that is just responsible for a returning a data count.

 $scope.m = {
        dataDetailedDs: new kendo.data.DataSource({
          type: "read",
          transport: {
            read: {
              url: "api/Data",
              dataType: "json"
            }
          },
 schema: {
            type: "json",
            data: "value",
            total: function() {
              $http.get('api/Data/NumberOfRecords').
                success(function(d) {
                  $scope.m.dataDetailedDs.total = d;
                  //also tried 
                 //return d;
                 //
                 //also tried
                 //return 10000;
                });
            },
            model: {
              fields: {
                Name: { type: "string" },
                ProjectId: { type: "number" },
                DataTypeId: { type: "number" },
                AlternativeName: { type: "string" },
                Guid: { type: "string" },
                Hashcode: { type: "string" },
                LastmodifiedTime: { type: "date" }
              }
            }
          },
          pageSize: 20,
          serverPaging: true,
          serverFiltering: true,
          serverSorting: true,

I can verify the success call back occurs but I cant get the grid to update itself to recognise it has pages. I assume this is because the total rest call is async and the grid doesn't then become updated.

I guess this is the wrong way to go about it, please can you help?
I didn't particularly want to wrap my entity objects in another object which has a field containing the total number of records...

As an aside i was using odata previously and got all this for free which was great until i ran into performance problems in sql server due to the generated queries from the entity framework. Sp_exexcute sql is doing lots of parameter sniffing and causing bad execution paths so queries are timing out. If a tweak the queries myself within sql server and add option recompile i can resolve the parameter sniffing bad execution path performance issues but unfortunately I don't have any control over the generated queries. if you have any thoughts on this and how to get around the issue I would also appreciate it!

Thanks for your help!
Doug



2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 11 Mar 2014, 12:59 PM
Hi Douglas,

The schema.total option is immediately evaluated which means that retrieving it with an ajax request won't work. You need to either return the total field as part of your initial read response or use a synchronous request:

total: function() {
        var count = 0;
        $.ajax( {
              url: "...",
              async: false
        })
        .success(function(total) {
              count = total;
        });
}

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Douglas
Top achievements
Rank 1
answered on 11 Mar 2014, 01:22 PM
Thanks for the quick response! - Just what i needed.

Of course i meant execution plan not path above!
Tags
Data Source
Asked by
Douglas
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Douglas
Top achievements
Rank 1
Share this question
or