Search code examples
jqueryangularjsinfinite-scrollnginfinitescroll

Why isn't ngInfiniteScroll working for tables?


I am trying to implement ngInfiniteScroll on my table with ng-repeat on <tbody> However, it doesn't get triggered when I reach the end of page.

<div infinite-scroll="list.getMoreItems()">
    <table md-table md-row-select>
        <thead md-head>
           <tr md-row>
                <th md-column><span>Id</span></th>
                <th md-column><span>Item</span></th>
            </tr>
        </thead>
       <tbody md-body ng-repeat="data in list.items">
           <tr md-row><td md-cell>{{data.title}}</td></tr>
           <tr md-row><td md-cell>Click here </td></tr>
       </tbody>
   </table>
</div>

My getMoreItems() does nothing more than throw an alert for now.

ngInfiniteScroll is configured correctly as it does execute getMoreItems() on page load but never after that.


Solution

  • The issue was with the viewport to scroll calculation. Removing overflow-y:hidden from the container that contains ng-repeat solved the problem.

    <div id="holdList" infinite-scroll="list.getMoreItems()">
        <table md-table md-row-select>
            <thead md-head>
               <tr md-row>
                    <th md-column><span>Id</span></th>
                    <th md-column><span>Item</span></th>
                </tr>
            </thead>
           <tbody md-body ng-repeat="data in list.items">
               <tr md-row><td md-cell>{{data.title}}</td></tr>
               <tr md-row><td md-cell>Click here </td></tr>
           </tbody>
       </table>
    </div>
    
    
    #holdList
    {
       height: 100%;
       overflow: auto;
    }