svelte-grid icon indicating copy to clipboard operation
svelte-grid copied to clipboard

Nested grid

Open analytically opened this issue 6 years ago • 10 comments

Hi, I'm trying to nest the grid in another grid, but not succeeding. Is this something that should work? Thanks

analytically avatar Sep 30 '19 17:09 analytically

It's possible, but it's a little more complicated.I'll show you the code tomorrow.

vaheqelyan avatar Sep 30 '19 19:09 vaheqelyan

Try this repl

I do not why but bind:items={nestedOne} crashes my firefox. I also suggest you limit the maximum width and height of elements in nested grids

vaheqelyan avatar Oct 01 '19 12:10 vaheqelyan

If I'm not mistaken bind:items={nestedOne} does not give problems in an earlier version of svelte

vaheqelyan avatar Oct 01 '19 12:10 vaheqelyan

Works indeed.

analytically avatar Oct 01 '19 12:10 analytically

How can I have Svelte update the nested grid via $:? Currently it's updating the 'parent' grid but not the nested one when the items change.

analytically avatar Oct 04 '19 16:10 analytically

Currently it's updating the 'parent' grid but not the nested one when the items change.

Can you go into more detail?

vaheqelyan avatar Oct 04 '19 17:10 vaheqelyan

When changing the items.nestedItems the nested grid isn't updated.

analytically avatar Oct 04 '19 17:10 analytically

let nestedItems = [...nestedItems, newNestedItem] items = [...items, {...gridHelp.item(...), nested: true, nestedItems = nestedItems}]

analytically avatar Oct 04 '19 17:10 analytically

This is my version But svelte does not react to it

items = items.map(val => {
  if (val.nested) {
    return {
      ...val,
      nestedItems: [
        ...val.nestedItems,
        ...[gridHelp.item({ x: 2, y: 0, w: 1, h: 2, id: id() })]
      ]
    };
  }
  return val;
});

However if you change for example the id it will work

If you change in a changeable way like this

items[0].nestedItems = [...items[0].nestedItems, ...newItem]; // Will not work
items[0].nestedItems = []; // Will work

vaheqelyan avatar Oct 04 '19 18:10 vaheqelyan

This is caused by the <Nested/> component. repl

vaheqelyan avatar Oct 05 '19 08:10 vaheqelyan