vaheqelyan / svelte-grid

A responsive, draggable and resizable grid layout, for Svelte. [NOT MAINTAINED]
https://svelte-grid.now.sh/
MIT License
970 stars 58 forks source link

NaN width and height #83

Closed MarcGodard closed 3 years ago

MarcGodard commented 3 years ago

I just copied the most basic example without any styling:

  const id = () => "_" + Math.random().toString(36).substr(2, 9);

  let items = [
    gridHelp.item({ x: 0, y: 0, w: 2, h: 2, id: id() }),
    gridHelp.item({ x: 2, y: 0, w: 2, h: 2, id: id() }),
  ]

and

    <Grid cols={3} bind:items={items} let:item={item}>
      <div>{item.id}</div>
    </Grid>

This is what shows in the console.

Screen Shot 2021-03-07 at 3 07 30 PM

Can't figure out what i am missing.

vaheqelyan commented 3 years ago

Take a look at this example https://github.com/vaheqelyan/svelte-grid/blob/master/www/src/routes/examples/basic.svx cols -> it is a 2d array. [ [1000, 6], [800, 3] ], breakpoint size, column size.

suppose that if your container is 1000px wide, your columns change by six, etc. so it changes to 6, then it will search for your item and find the key 6.

gridHelp.item({
  6: { w: N, h: N, x: N, y: N },
  3: { w: N, h: N, x: N, y: N },
})
MarcGodard commented 3 years ago

@vaheqelyan Thanks for your help. However, I changed the existing cols attribute with the 2d array, and same results.

  const id = () => "_" + Math.random().toString(36).substr(2, 9);

  const cols = [
    [ 1100, 6 ],
  ]

  let items = [
    {
      6: gridHelp.item({
        x: 0,
        y: 0,
        w: 2,
        h: 2,
      }),
      id: id(),
    },

    {
      6: gridHelp.item({
        x: 2,
        y: 0,
        w: 2,
        h: 2,
      }),
      id: id(),
    },
  ];

and

    <Grid bind:items={items} let:item={item} {cols}>
      <div>{item.id}</div>
    </Grid>
vaheqelyan commented 3 years ago

You missed creating a container. 1100is the width of your container.

<style>
.container {
  max-width: 1100px;
  width: 100%;
}
</style>

<div class=container>
  <Grid />
</div>
MarcGodard commented 3 years ago

Now is working for width but not height. lol

I am guessing I need to do the same for height?

Screen Shot 2021-03-09 at 6 12 26 PM

Will play more with this.

vaheqelyan commented 3 years ago

Please specify rowHeight

vaheqelyan commented 3 years ago

Feel free to reopen

MarcGodard commented 3 years ago

Sorry, but I built my own it its good. Thanks for your help.