Grid DataSource Total Function not doing what I expect

5 posts, 0 answers
  1. Marius
    Marius avatar
    6 posts
    Member since:
    Mar 2016

    Posted 17 Mar Link to this post

    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.

  2. Marius
    Marius avatar
    6 posts
    Member since:
    Mar 2016

    Posted 17 Mar in reply to Marius Link to this post

    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?
  3. Kendo UI is VS 2017 Ready
  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 22 Mar Link to this post

    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!
     
  5. Marius
    Marius avatar
    6 posts
    Member since:
    Mar 2016

    Posted 22 Mar in reply to Nikolay Rusev Link to this post

    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

  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 24 Mar Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready