Note that there are some explanatory texts on larger screens.

plurals
  1. POMirroring a HTML table with Javascript/jQuery
    primarykey
    data
    text
    <p>I'm trying to mirror a table, with a dynamic grid like 4x4, 7x7, or 9x2.</p> <p>I dynamically create this: </p> <pre><code>&lt;table id="mainTable" class="mainClassTable" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tbody&gt; &lt;tr id="row-1"&gt; &lt;td id="col-1" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-2" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-3" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-4" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;/tr&gt; &lt;tr id="row-2"&gt; &lt;td id="col-1" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-2" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-3" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-4" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;/tr&gt; &lt;tr id="row-3"&gt; &lt;td id="col-1" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-2" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-3" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;td id="col-4" onclick="imgClick(this)"&gt;Stuff Here&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>I'm wondering what would be the best way for each row to get col-1 to move to col-4, and col-2 on col-3. And with uneven columns I fear it would be more complicated.</p> <p>I found something about shuffling rows, but I want to shuffle columns.</p> <p>I'm thinking about using jQuery selectors to tediously repositioning each td, but i'm wondering if there might be a nice jquery plugin to rearrange tables.</p> <p>I don't want draggable, I just want one click to mirror the table (not the contents).</p> <p>/Edit<br> So I tried making each col ID unique, but I ended up with this steaming pile of code:</p> <pre><code>function makeGrid(content, rowCount, colCount) { //Empty TD string tableVarSet = ""; //gridTotal = gridTotal - gridTotal; //Loop for multiple columns for (c=1;c&lt;=colCount;c++) { //make column var tableVarSet = tableVarSet + makeColumns(content, c); } //Loop for multiple rows for (i=1;i&lt;=rowCount;i++) { //Make new Row rowVarToAdd = "&lt;tr id=TMPR&gt;"+tableVarSet+"&lt;/tr&gt;"; $("#mainTable").append(rowVarToAdd); //Set new RowID rowName = "row-" + i; $("#TMPR").attr('id', rowName); } }; function makeColumns(content, count) { //Split String tableVar1 = "&lt;td id=col-" tableNum = count; tableVar2 = " onClick='imgClick("; tableFunction = "this" ; tableVar3 = ")'&gt;"+content+"&lt;/td&gt;"; //Combine Strings: colVar = tableVar1 + tableNum + tableVar2 + tableFunction + tableVar3; //Return result return colVar; }; </code></pre> <p>So, yeah it kind of works but It can probably be a lot easier. (any ideas?)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload