angular2-masonry icon indicating copy to clipboard operation
angular2-masonry copied to clipboard

Order change via pipe is not detected

Open cpoissonnier opened this issue 9 years ago • 4 comments

Hello,

When I sort my list with a custom pipe, the order is not changed when I use angular2-masonry. Without angular2-masonry, it works.

<masonry>
	<masonry-brick *ngFor="let item of list | sortBy:dynamicProperty">
		<dsv-item [item]="item"></dsv-item>
	</masonry-brick>
</masonry>

Is there a way to make masonry detect these changes?

cpoissonnier avatar Jan 02 '17 17:01 cpoissonnier

I'm having the same problem on my app. This is quite annoying and it would be great to have a solution soon.

andreasonny83 avatar Mar 19 '17 15:03 andreasonny83

Try it.

private elements: HTMLElement[] = []; private onEventNewElement: EventEmitter<any> = new EventEmitter<any>();

ngOnInit() {
    this.onEventNewElement.subscribe(() => {
            if (this.elements.length > 0) {
                let el = this.elements[0];
                this.elements.splice(0, 1);
                this.initElementImageload(el);
            }
        });
}
private initElementImageload(element) {
        imagesLoaded(element, (instance: any) => {
            this._element.nativeElement.appendChild(element);
            this._msnry.appended(element);
            this.onEventNewElement.emit();
            this.layout();
        });
}
public add(element: HTMLElement) {
        if (this.useImagesLoaded) {
            this.elements.push(element);
            this._element.nativeElement.removeChild(element);
        }
        if (this._element.nativeElement.children.length === 0) {
            this.onEventNewElement.emit();
        }
}

niveo avatar Sep 27 '17 12:09 niveo

Hi @cpoissonnier . I had this problem too and fixed this problem. So here is solution. When order value is changed you need to destroy masonry and reload it. Assign showMasonry attribute to masonry in html like

<masonry *ngIf="showMasonry ">

and initially give it true value. When order value is changed

onOrderValueChanged() { this.showMasony = false; setTimeout(() => this.showMasony = true, 20); } Hope it helps!

vugar005 avatar Nov 08 '17 14:11 vugar005

Another way is to force masonry to draw the layout again by calling

this.masonry._msnry.reloadItems();
this.masonry._msnry._isLayoutInited = false;
this.masonry.layout()

Panos-Bletsos avatar Nov 09 '17 08:11 Panos-Bletsos