ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

set scrollbar handle size based on total number of elements?

Open mattsawyer77 opened this issue 10 years ago • 4 comments

I've combed the API docs, Google, SO, and haven't found anything about this. But I was wondering if it's possible to size the scrollbar based on the total number of elements that could be retrieved. In other words, the scrolling experience would appear to be seamless to the user because the size of the scroll handle would remain essentially constant while scrolling all the way from the top to the bottom and back, instead of the scrollbar size jumping each time a page of data is loaded.

I realize this may not be valuable if the client doesn't know the total number of rows, but in our case we always know the total, so it'd be trivial to set something via the grid API that causes the scrollbar container to size itself and make the scrollbar handle look like the right size.

mattsawyer77 avatar Mar 22 '16 01:03 mattsawyer77

I wanted to implemented something similar to what your propose, but the scrollbar is dynamic adjusted base on the length grid data.

What I did is something called lazy loading which does not come with ui-grid (ui grid has infinite loading). To hack around, since I know the total item, I have to create an array with value of 0 with the length of the total item. So by doing this, the scrollbar will show proper size according to the data length.

Then what you need to do is when user scrolls, you want to dynamically retrieve the data from backend, and then append that set of data to data grid depend on where the scroll bar's position.

register scrollEnd event to your grid gridApi.core.on.scrollEnd($scope, function (row) { $scope.scrollChanged(row); }); Create a function called scroll change, where you can calculate which row or page should I retrive from backend by Math.round(row.newScrollTop / row.grid.options.rowHeight)

Then you just need to retrieve data from backend like you did for paging.

Let me know if it helps.

stevenlius avatar Mar 24 '16 13:03 stevenlius

Performance wide, I am running on localhost with dataset over 80k. Init data grid takes around 100ms. Lazy loading next chunk of data takes 15ms

stevenlius avatar Mar 24 '16 13:03 stevenlius

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 23 '18 04:05 stale[bot]

This issue has been automatically closed because it has not had recent activity. If you believe that this is still an issue in the latest version, feel free to re-open it. Thank you for your contributions.

stale[bot] avatar Jun 22 '18 05:06 stale[bot]