I am trying to dynamically add div's (which will be the target for jqplot graphs) to a tab panel using Foundation 6. I want the divs to be in a column layout in the row. I can get the divs in a row but each div ends up being in a row by itself instead of being a column element in the row.
I want this layout: Layout I want
I have been using the code below to create the row div in the "graph1" panel:
var dynDivR1 = document.createElement("div");
dynDivR1.id = ("dynRow1");
dynDivR1.class = "row";
document.getElementById("graph1").appendChild(dynDivR1);
I then go into a loop to create the actual images (get the data, create the jqplot graph). Within the loop I create the graph div using the code below:
var dynDiv2 = document.createElement("div");
dynDiv2.id = ("dynDiv2" + divno2);
dynDiv2.class = "small-7 medium-3 large-3 columns";
dynDiv2.style.height = "200px";
dynDiv2.style.width = "200px";
dynDiv2.style.backgroundColor = 'white';
document.getElementById("dynRow1").appendChild(dynDiv2);
var plotInDiv2 = simplePlot(dynDiv2.id, lineDat2, sensorNames);
divno2 +=1;
simplePlot is a function that creates the graph using jqplot. This code works in the sense that divs are dynamically created, the graphs are placed in them. The problem I have is the layout: because I will have many graphs I want them in columns going across the page, not rows down the page (I will eventually have to have rows and columns but for now I am just trying to solve the column problem).
I tried removing the column width and height attributes in the image div but that also did not work (just got full width images / divs).
When I look at the resulting HTML the div's I have created do not seem to contain the class information. So for example the dynRow1 div looks like this (see actual HTML below):
<div id="dynRow1">
It does not have class = row attribute. When I look at the div (console.log) immediately after creation the class = row is there.
I tried inserting an additional column class div in the row like this (and then attach the plot div to that) but it did not work:
<div class="medium-6 columns">
I am stuck and would greatly appreciate any suggestions or pointers others can give.
Thank you very much.
Added 26/12/16 This is the HTML I am getting (I have not included the closing tags - they are there, the page loads and works without error in Firebug:
<div class="tabs-content" data-tabs-content="dy-tabs-2">
<div id="data1" class="tabs-panel" role="tabpanel" aria-hidden="true" aria-labelledby="data1-label">
<div id="graph1" class="tabs-panel is-active" role="tabpanel" aria-hidden="false" aria-labelledby="graph1-label">
<div id="dynRow1">
<div id="dynDiv21" class="jqplot-target" style="height: 200px; width: 200px; background-color: white; position: relative;">
<div id="dynDiv22" class="jqplot-target" style="height: 200px; width: 200px; background-color: white; position: relative;">
Then this is a clip of the screen shot of the resulting HTML Clipped screen shot from HTML page
Thanks Again
Thanks to Chris O for the useful suggestions. I have used Chris's suggestions as a basis for the following solution which works.
The createRowColDivs function just creates the row div so I can use it in other processes. Could easily have kept those processes in staticPlots function.
This code gives me the row by column plot layout I was after.
Thanks Chris for the snippet that saw me on my way. One thing I had to change in your code was attaching the row div before I defined the col divs. it also took me way too long to figure out I needed to use lx to create unique id's for each plot.
Always appreciate suggestions for improving the code if anyone cares to.