vaheqelyan / svelte-grid

A responsive, draggable and resizable grid layout, for Svelte.
https://svelte-grid.now.sh/
MIT License
948 stars 57 forks source link

Automatically place item in grid #96

Open asjur opened 3 years ago

asjur commented 3 years ago

I've been trying to find but is there a way to automatically lay out a set of items in the grid provided that you are specifying the size of each item? I'd like to avoid having to calculate positions if possible.

Edit: I found that fillSpace={true} with gridHelp.adjust can solve this issue somewhat. However I need to pass a column count, so I have gridHelp.adjust(items, 5) as 5 is the initial column size, however if the user comes from a mobile their column size is obviously different and it doesn't working. Can I get active column size somehow?

vaheqelyan commented 3 years ago

you can get the current column by listening for the following events.. on:mount, on:resize, on:change

(event) => event.details.cols

https://github.com/vaheqelyan/svelte-grid/blob/master/www/src/routes/examples/responsive-local-storage.svx#L71 https://github.com/vaheqelyan/svelte-grid/blob/master/www/src/routes/examples/responsive-local-storage.svx#L20