The grid-auto-flow CSS property specifies exactly how auto-placed items get flowed into the grid.
object.style.gridAutoFlow = "value";
<'grid-auto-flow'> = [ row | column ] || dense
Places items by filling each row in turn, adding new rows as necessary.
Places items by filling each column in turn, adding new columns as necessary.
Attempts to fill in holes earlier in the grid if smaller items come up later.