question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change array order breaks masonry template 🤔

See original GitHub issue

My app consist in an array of item that can be ordered by some filter criteria using a MAT MENU to select the preferred criteria

image

But when I change the order or my items array masonry is rendered completely wrong, for example:

image

I have tried as documentation says:

Set [ordered]="true" in template, also use masonry functions to render again when my array is re-ordered

this.masonry.reloadItems();
this.masonry.layout();

This is how it looks ordered at init

image

Some times the order is applied fine but mostly is rendered wrong

This is my reproduction repo in github https://github.com/AlonsoK28/amazmation-app-2/tree/feature/update-layout because I cant upload it to stackblitz 😢

I hope you can help me 😜👏

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
wynfredcommented, Jan 11, 2022

Hi, didn’t realize the order is wrong. Could you try this? Thanks!

  setCurrentOrderBy(el: OrderByDefinition){
    this.orderByPipeConfig = el.config;
    // order all items in array, not only 15
    this.itemsLimit = 15;
    let tempMasonryItems = this.orderPipe.transform(this.offersFromService, this.orderByPipeConfig.expression, this.orderByPipeConfig.reverse, this.orderByPipeConfig.caseInsensitive, this.orderByPipeConfig.comparator).slice(0, this.itemsLimit);
    this.currentMasonryItems = [];
    setTimeout(() => {
      this.currentMasonryItems = tempMasonryItems;
    });
  }
1reaction
wynfredcommented, Jan 3, 2022

Hi, it seems like the reloaditems function is causing the problem. Try remove both reloadItems and layout

  showMoreImages() {
    this.itemsLimit += 15;
    this.tempMasonryItems = this.orderPipe.transform(this.offersFromService, this.orderByPipeConfig.expression, this.orderByPipeConfig.reverse, this.orderByPipeConfig.caseInsensitive, this.orderByPipeConfig.comparator).slice(0, this.itemsLimit);
    this.currentMasonryItems = this.tempMasonryItems;
    // this.masonry?.reloadItems();
    // this.masonry?.layout();
  }

  setCurrentOrderBy(el: OrderByDefinition){
    this.orderByPipeConfig = el.config;
    // order all items in array, not only 15
    this.itemsLimit = 15;
    this.tempMasonryItems = this.orderPipe.transform(this.offersFromService, this.orderByPipeConfig.expression, this.orderByPipeConfig.reverse, this.orderByPipeConfig.caseInsensitive, this.orderByPipeConfig.comparator).slice(0, this.itemsLimit);
    this.currentMasonryItems = [];
    this.currentMasonryItems = this.tempMasonryItems;
    // this.masonry?.reloadItems();
    // this.masonry?.layout();
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Masonry effect - How can I change the order of the blocks?
You can do this effect using CSS grid .columns { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: minmax(10px, ...
Read more >
Pushing a new object in the array does not rerender ... - GitHub
When I try to post an API request and get the response and push that object into the array. The masonry will not...
Read more >
Masonry layout - CSS: Cascading Style Sheets | MDN
Masonry layout is a layout method where one axis uses a typical strict grid layout, most often columns, and the other a masonry...
Read more >
Masonry / portolio grid: How can I change the order of sort ...
I'd like to arrange the sort options (when using masonry or portfolio grid) by my own preferences. At the moment they appear in...
Read more >
A Lightweight Masonry Solution - CSS-Tricks
In order to do this, we go to about:config in Firefox and search for “masonry.” This brings up the layout.css.grid-template-masonry-value.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found