Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created March 21, 2015 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katowulf/c74b6e2d047c9e2eaaa9 to your computer and use it in GitHub Desktop.
Save katowulf/c74b6e2d047c9e2eaaa9 to your computer and use it in GitHub Desktop.
Example of infinite scroll using ui-grid and Firebase (uses http://firebase.github.io/firebase-util/)
var app = angular.module('app', ['firebase', 'ui.grid', 'ui.grid.infiniteScroll']);
app.controller('ctrl', function($scope, $firebaseArray) {
var baseRef = new Firebase('https://fbutil.firebaseio.com/paginate');
var scrollRef = new Firebase.util.Scroll(baseRef, 'number');
//$scope.data = $firebaseArray(scrollRef);
$scope.opts = {
columnDefs: [
{name: '$id', displayName: 'ID'},
{name: 'string'},
{name: 'number'},
{name: 'timestamp', displayName: 'Date'},
{name: '$priority', displayName: 'Priority'}
]
};
$scope.opts.data = $firebaseArray(scrollRef);
scrollRef.scroll.next(25);
$scope.opts.onRegisterApi = function(gridApi){
gridApi.infiniteScroll.on.needLoadMoreData($scope,function(){
scrollRef.scroll.next(25);
});
gridApi.infiniteScroll.on.needLoadMoreDataTop($scope,function(){
scrollRef.scroll.prev(25);
});
$scope.opts.data.$watch(function() {
$scope.$evalAsync(function() {
gridApi.infiniteScroll.dataLoaded();
});
});
};
});
<div ui-grid="opts" class="grid" ui-grid-infinite-scroll></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment