andrewmcgivery / ionic-ion-autoListDivider

Gives a set of directives for automatically adding in list dividers for an ng-repeat. (Works for Alphabetical or by Categories)
75 stars 21 forks source link

On list refresh #6

Open freekrai opened 9 years ago

freekrai commented 9 years ago

If you have set up your list to let you delete items from it, I've found that when the list is refreshed, the items appear at the top and then the letters appear at the bottom.

Before item was deleted:

screenshot 2015-02-22 20 06 31

After item was deleted:

screenshot 2015-02-22 20 06 40

scotthooker commented 9 years ago

Yes I have the same issue. The old headers are not cleared on pull to refresh.

yang-zhang-syd commented 9 years ago

I have added a few lines to remove the dividers from list which is enough for my app.

angular.module('ionic.ion.autoListDivider',[])

.directive('autoListDivider', function($timeout) {
var lastDivideKey = "";

return {
    link: function(scope, element, attrs) {
        var key = attrs.autoListDividerValue;

        var dividers = document.getElementsByClassName("item-divider");

        while(dividers.length > 0)
        {
            dividers[0].parentNode.removeChild(dividers[0]);
        }

        var defaultDivideFunction = function(k){
            return k.slice( 0, 1 ).toUpperCase();
        }

        var doDivide = function(){
            var divideFunction = scope.$apply(attrs.autoListDividerFunction) || defaultDivideFunction;
            var divideKey = divideFunction(key);

            if(divideKey != lastDivideKey) { 
                var contentTr = angular.element("<div class='item item-divider'>"+divideKey+"</div>");
                element[0].parentNode.insertBefore(contentTr[0], element[0]);
            }

            lastDivideKey = divideKey;
        }

        $timeout(doDivide,0)
    }
}

});

Taylorsuk commented 9 years ago

I have this same issue when doing any sort of splice etc for deleting...

itrunks commented 9 years ago

save my time :-)

itrunks commented 9 years ago

if i insert new item some of header missed and show to merge the items How to avoid this situation

giorgiofellipe commented 9 years ago

+1

junerockwell commented 8 years ago

+1

shashu10 commented 8 years ago

+1

joubo commented 8 years ago

+1

Nyl000 commented 8 years ago

+1 Same bug when I bind a filter on the ng-repeat. (Looks like the link function triggers only when items appear but never when items are filtered..) I think that issue comes from the angular core..

jeandat commented 8 years ago

+1

mavericks065 commented 8 years ago

Thanks for the fix.