Grid without total count

10 posts, 1 answers
  1. Alex
    Alex avatar
    16 posts
    Member since:
    Oct 2011

    Posted 04 Sep 2013 Link to this post

    I have a grid that is currently server bound and pageable showing data read from a database. I've noticed that if there is a lot of data and the underlying query is complicated rendering the page can take a long time. Getting the actual rows is not too bad as it just gets the first 20 (or a single page). The time consuming part is getting the count of rows. 

    I would be happy not to know the total number of rows or even the number of pages. So I've tried turning off Info and Numeric paging options, but the count is still being calculated.

    I've tried switching to a virtual scrolling grid as this seems to be Kendo's recommended approach for large datasets, but it seems this also performs a count so that it knows how big a scrollbar to show.

    Is there any way to use the kendo grid without performing a count on the total number of items?
  2. beauXjames
    beauXjames avatar
    20 posts
    Member since:
    Aug 2012

    Posted 04 Sep 2013 Link to this post

    Can you show how you're initializing your grid with an example format of the '20 rows' you are pulling down? Are you certain that you're not loading in your entire data set? Chances are, you are and you need to look @ your network traffic through Fiddler or just the WebDevNetwork sniffer in Chrome/FF if you're not loading your page with the response data, but pulling it down asynch. What kendo grid shows is always just a partial of the entire context.

    How many rows of data are you bringing to the page?
  3. Kendo UI is VS 2017 Ready
  4. Alex
    Alex avatar
    16 posts
    Member since:
    Oct 2011

    Posted 05 Sep 2013 Link to this post

    Thanks for your reply. Yes I'm certain that it's only retrieving the '20 rows'. I've looked in Oracle at the queries that are being run and there is a where rownum < 20. However there is also a query that counts the data.

    I'm using the asp.net mvc wrappers. Grid is server bound, In the controller I define an IQueryable that is then passed in to the constructor Kendo().Grid<MessageSummary>(messages). This allows the default server binding to apply the appropriate Skip, Take, Filters etc defined in the grid.

    Getting the actual rows is fairly good performance, but the default server binding also calls Count() on the datasource, which is rather an expensive query in my case. As an example the total count of matching rows might be something like 2,000,000. However these 2,000,000 rows will be in a table with several million rows that do no match the query, performing a count on this query can be expensive.
  5. beauXjames
    beauXjames avatar
    20 posts
    Member since:
    Aug 2012

    Posted 05 Sep 2013 Link to this post

    Post the configuration of your kendo grid, including all the options you currently have set.
  6. Answer
    Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 06 Sep 2013 Link to this post

    Hello Alex,

    The information about the total number of data items is required and cannot be skipped. As an alternative to the Grid's native databinding methods, you can use custom binding and optimize the queries according to your preferences:

    http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/custom-binding

    You will still need information about the total data count, but you can retrieve it in a different way, if needed.

    Also, please avoid posting duplicate threads in the forum and the ticketing system. Thank you for understanding.

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. Erik Gantar
    Erik Gantar avatar
    7 posts
    Member since:
    Oct 2005

    Posted 11 Sep 2013 Link to this post

    Same problem,
    why in  "virtual scrolling on" you need count 

    IDEA
    without count 
    no of # 2000000000
    page size 20 #


    1. read first 21 record and (if you get more than 21 records return 20 and bind it to the grid + show next button) if you get less than 21 # return it all and there is no next button 
    2. in the next page you can also turn on prev button because you know that 1 page is loaded before and read # from 20-41 (same logic as step 1 )
    3. ..........

    erik



  8. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 11 Sep 2013 Link to this post

    Hi Erik,

    Total count is required when using virtual scrolling, because this functionality is actually a paging that looks like scrolling. Only a [pageSize] number of records are rendered inside the Grid. The page that is displayed depends on the scrollbar position. This scrollbar is not real and its rendering also depends on the total number of records.

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  9. Erik Gantar
    Erik Gantar avatar
    7 posts
    Member since:
    Oct 2005

    Posted 11 Sep 2013 Link to this post

    Sory to use word virtual scrolling the IDEA is to think about new feature, paging without count and without pages like 1,2,3,4...last and paging like 
     [prev], [next] for what you don't need count. 
  10. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 11 Sep 2013 Link to this post

    Hi Erik,

    Such an implementation and behavior is theoretically possible to achieve (even currently with custom code using the Kendo UI DataSource and Grid APIs), but we don't regard it as user-friendly and don't recommend it.

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  11. Alex
    Alex avatar
    16 posts
    Member since:
    Oct 2011

    Posted 11 Sep 2013 Link to this post

    I've part implemented this for a server bound grid. I've not done Grouping yet (not sure if I will). The hardest part is that the Grid desperately wants a Total, and if you don't provide it with one lots of things seem to stop working. To work around this I tell it a lie on each request that the total is just enough to equal one more page of data.

    For any interested party here are some steps/tips:
    In the Controller:
    1. Take a DataSourceRequestParameter (if null check that Prefix is correct)
    2. Set  the pagesize to a default if not set. (make sure it's the same default as in the view!)
    3. Get an IQueryable for your data
    4. apply request.filters using Kendo extension method "Where"
    5. apply request.sorts using Kendo extension method "Sort"
    6. Calculate the number of items to skip (request.Page-1) * request.Page
    7. Apply the skip
    8. Apply a Take as request.PageSize+1 (+1 so that we know if there is at least one item on the next page)
    9. Execute the query (query as IQueryable<ItemType>).ToList()
    10. Record the total as being the number of items returned from the query + the skip calculated earlier. (If 0 items returned probably best to return 0, but not fully tested trying to access a page beyond the limit)
    11. Store the first PageSize number of items from the query (throwing away the last item).
    In the View:
    1. Use constructor that takes IEnumerable, to pass in the results of the query (apart from the last item)
    2. Turn on "EnableCustomBinding"
    3. In the DataSource specify the Total that we calculated in the Controller
    4. In the Pageable configuration turn off Numeric, change the Messages.Display to "{0} - {1}"
    I've currently hidden the "Last page" button using a hacky bit of CSS:
    a[title="Go to the last page"]{ display:none;}
    I think it would be nice to include the Last Page, with the query's sort direction being reversed, but I've not done this yet, and I think it would require some interception at some point so that it's not just "GetPage2" but "GetLastPage"

    Looking at how the default server binding works (using Telerik JustDecompile) is a valuable resource in terms of duplicating the default server binding (omitting the call to Count()). If I go ahead to do Grouping I imagine this will be how I will do it.

    Hope that helps someone!
Back to Top
Kendo UI is VS 2017 Ready