Best open-source grid with smooth, infinite scrolling

后端 未结 2 1383
庸人自扰
庸人自扰 2021-02-05 21:26

When I started working on my current project I was given quite an arduous task - to build something that in essence suppose to replace big spreadsheet people use internally in m

相关标签:
2条回答
  • 2021-02-05 22:04

    Maybe the problem is not with the existing widgets but more with the way you use it. You have to understand that over 2000 bindings angular digest cycles can take too long for the UI to render smoothly. In the same idea the more html nodes you have on your page, the more memory you will use and you might reach the browser capacity to render so many nodes in a smooth way. This is one of the reason why people use this "lame" pagination.

    At the end what you need to achieve to get something "smooth" is to limit the amount of displayed data on the page. To make it transparent you can do pagination on scroll.

    This plunker shows you the idea, with smart-table. When scrolling down, the next page is loaded (you will have to implement the previous page when scrolling up). And at any time the maximum amount of rows is 40.

    function getData(tableState) {
    
                //here you could create a query string from tableState
                //fake ajax call
                $scope.isLoading = true;
    
                $timeout(function () {
    
                    //if we reset (like after a search or an order)
                    if (tableState.pagination.start === 0) {
                        $scope.rowCollection = getAPage();
                    } else {
                        //we load more
                        $scope.rowCollection = $scope.rowCollection.concat(getAPage());
    
                        //remove first nodes if needed
                        if (lastStart < tableState.pagination.start && $scope.rowCollection.length > maxNodes) {
                            //remove the first nodes
                            $scope.rowCollection.splice(0, 20);
                        }
                    }
    
                    lastStart = tableState.pagination.start;
    
                    $scope.isLoading = false;
                }, 1000);
    
            }
    

    This function is called whenever the user scroll down and reach a threshold (with throttle of course for performance reason)

    but the important part is where you remove the first entries in the model if you have loaded more than a given amount of data.

    0 讨论(0)
  • 2021-02-05 22:06

    I'd like to bring your attention towards Angular Grid. I had the exactly same problems as you said, so ended up writing (and sharing) my own grid widget. It can handle very large datasets and it has excellent scrolling.

    0 讨论(0)
提交回复
热议问题