Coder Social home page Coder Social logo

Updating layout about angular-grid-layout HOT 3 CLOSED

katoid avatar katoid commented on May 26, 2024
Updating layout

from angular-grid-layout.

Comments (3)

llorenspujol avatar llorenspujol commented on May 26, 2024 1

The solution to this error is never mutating the array. It is exposed on the Troubleshoot section, although is complicated to see sometimes, here is what it says:

Mutating the layout would cause an error like: 'ERROR TypeError: Cannot read property 'id' of undefined'. Never mutate the layout, always return a new instance when modifying it.

This is mainly because the Grid needs to know when the layout has changed, and the only way to do it now is just returning a new instance of the array every time it changes.

You can replace 'push' for this code (for example):
this.layout = [...this.layout, { id: '4', x: 0, y: 12, w: 3, h: 3 }];

from angular-grid-layout.

Loevbo avatar Loevbo commented on May 26, 2024

Thanks for your response. I didn't noticed the troubleshoot section (my bad).

When I run the code you provide it updates the array without any error's but the grid is not updated with the new item. Ready your troubleshoot section, I've also tried removing trackBy to make angular update but no luck

Here is the html

<ktd-grid [cols]="cols"
  *ngIf="showgrid"
  [rowHeight]="rowHeight"
  [layout]="layout" class="grid">
  <ktd-grid-item [dragStartThreshold]="20" *ngFor="let item of layout; trackBy:trackById"
    [id]="item.id" class="grid-item">
  </ktd-grid-item>
</ktd-grid>

from angular-grid-layout.

llorenspujol avatar llorenspujol commented on May 26, 2024

Have you checked that it is not a change detection issue? Maybe you are running the addItem() outside the zone. To check that, add an item, and after that, make a simple drag on some other grid item, does the item appear? If so, is a change detection issue.

If the above reproduction doesn't make your item appear, you would need to make a stackblitz reproduction of your issue, or provide more information about your code and context to see other possible sources of the error.

from angular-grid-layout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.