Famous / famous-angular

Bring structure to your Famo.us apps with the power of AngularJS. Famo.us/Angular integrates seamlessly with existing Angular and Famo.us apps.
https://famo.us/angular
Mozilla Public License 2.0
1.92k stars 275 forks source link

Adding item to ng-repeat list is only added to bottom, regardless of sorting #242

Closed 5inline closed 9 years ago

5inline commented 9 years ago

In an fa-scroll-view or fa-sequential-view with an ng-repeat inside, any items added to the ng-repeat array after render appear at the bottom, regardless of the sorting options in ng-repeat.

<fa-scroll-view>
    <fa-view ng-repeat="item in items | orderBy:name">
        {{item.name}}
    </fa-view>
</fa-scroll-view>

// List of items
$scope.items = [
    {name: 'Albert'},
    {name: 'Roger'},
    {name: 'Bob'},
    {name: 'Steve'}
];

// Execute after initial render
setTimeout( function()
{
    $scope.items.push({name:'Aaron'});
}, 1500);

On the initial load, the items will appear in the correct order. After that, 'Aaron' is always added to the bottom of the list.

Is there a way to retain the sorting when items are added after the initial render?

zackbrown commented 9 years ago

there is: check out fa-index On Oct 24, 2014 3:35 PM, "5 Inline" notifications@github.com wrote:

In an fa-scroll-view or fa-sequential-view with an ng-repeat inside, any items added to the ng-repeat array after render appear at the bottom, regardless of the sorting options in ng-repeat.

{{item.name}}

// List of items $scope.items = [ {name: 'Albert'}, {name: 'Roger'}, {name: 'Bob'}, {name: 'Steve'} ];

// Execute after initial render setTimeout( function() { $scope.items.push({name:'Aaron'}); }, 1500);

On the initial load, the items will appear in the correct order. After that, 'Aaron' is always added to the bottom of the list.

Is there a way to retain the sorting when items are added after the initial render?

— Reply to this email directly or view it on GitHub https://github.com/Famous/famous-angular/issues/242.

5inline commented 9 years ago

Awesome. That works for fa-scroll-view.

Does not work for fa-sequential-view, though not sure if it is intended to.

imheresamir commented 9 years ago

fa-index works on fa-sequential-view, and will work for fa-deck as well. Please see https://github.com/Famous/famous-angular/issues/236#issuecomment-59635947

zackbrown commented 9 years ago

This was a bug: if dynamic values are bound to fa-index (instead of constants like in the example you shared, @imheresamir ) then in some cases sorting wouldn't work because the directive would try to sort the values before they had been evaluated by Angular. There was a fix in place for this in fa-scrollview but it hadn't made it to fa-sequential-layout yet: just fixed this with 57e4b8d1b5143 . @5inline, if you try pulling down master, is this fixed for you?

imheresamir commented 9 years ago

Ahh gotcha. Thanks for clearing that up.

5inline commented 9 years ago

Yep, that fixes it. Thanks for the quick turnaround!