I am creating a grid and I need to append items into it from an array of Javascript objects.
The grid <div id="grid">
simply a div
container which needs to have 4 columns and infinite rows (to accommodate a varying quantity of objects that may be inserted into the grid).
The grid items, which will also be divs
, are based on objects that have attributes specifying their columns, row, width & height within the grid. They look like this:
c: 1
r: 3
x: 1
y: 1
columns: Just like a table
this defines which column the item starts at, and expands to the right according to the item's x
value.
row: The row the item is on.
x: The width of item in columns. The item width is always less than or equal to 4.
y: The height of the item in rows. The item height is always less than or equal to 2.
I need to write some javascript that will order, position and append these items within the grid based on these attributes. If it helps, the json data is coming from a similar grid created with the gridster.js library.
jQuery can be used.