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

Grid DataSource Total Function not doing what I expect

4 Answers 469 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Marius
Top achievements
Rank 1
Marius asked on 17 Mar 2016, 08:55 AM

Hi,

I have the following Problem: I have a Grid with remote Data Binding via Ajax request. When the Parameters for the Request Change and I call the read() Function again I also have to change the total Value, but the Data Request doesn't send the Total. This is done by a second Request that I send with a angular $http request. When I then call The Total Function it doesnt update and has some strange behaviour:

Total Method:

total: () =>
  return $scope.collectionSize

success Callback of getTotal request:

$scope.collectionSize = response.data
console.log "next log should be: " + $scope.collectionSize
console.log "but is: " +  $scope.grid.dataSource.total()

and the Console log on initial and second requests:

next log should be: 53
but is: 0
next log should be: 3
but is: 53

If I Call a $apply in the getTotal it says digest already in Progress. The Grid is initialised with the angularjs feature.

On initial load the Grid says ... of 53 Items.

On second Data load it says ...of 53 Items again.

And on the third call it then says ... of 3 Items.

So it is always one load behind, except on the initial load.

4 Answers, 1 is accepted

Sort by
0
Marius
Top achievements
Rank 1
answered on 17 Mar 2016, 09:54 AM
Okay so I found a Workaroud for this by calling grid.dataSource.read() only when the getTotal request finished, but I'm not entirely happy with it, since it has means longer loads. Is there any other way to reliably set the dataSource.shema.total value independently from the main Grid Configuration?
0
Nikolay Rusev
Telerik team
answered on 22 Mar 2016, 08:01 AM

Hello Marius,

 

I'm not sure I fully understand the scenario, but here is how DataSource works.

 

If you have configured serverPaging: true the server is responsible for returning current page data items and the total count of items. Otherwise things like Grid pager will not be able to form its structure properly.

 

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Marius
Top achievements
Rank 1
answered on 22 Mar 2016, 08:19 AM

Hi Nikolay,

yes I have serverPaging set to true, but the Backend I am working with was not build for KendoUI and it only returns the total count of items on a seperate request, which I cannot change.

My Problem/missunderstanding was that I thought calling the total() Function on the dataSource would actually execute the function that I declared on the dataSource initialisation (like the read() function). What happens though is that it only returns the total Item count it currently has stored (does not recalulate).

So as I said the solution/workaroud I use now is that I first call the getTotal function with the Server request to get the total Item count and when that finishes I call the Read() function on the dataSource.

 

Regards,

Marius

0
Nikolay Rusev
Telerik team
answered on 24 Mar 2016, 07:55 AM

Hello Marius,

 

I see what you expect, but this is not the case for the DataSource. Regardless of the server implementation the response must return the data and the total in one request.

 

Calling total function only returns currently fetched total count, it doesn't trigger another request.

 

In this case you could implement custom transport where to sync both requests. Here is a quick simulation - http://dojo.telerik.com/@rusev/eLOcI

 

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