Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best way to solve this in Javascript is:</p> <p>Give the Tr.. a unique name. for eg: X_Y,X_Z,A_Y,A_Z</p> <p>Now add a hidden lable or text Box which gives the sorting order from the server i.e When the page renders I want to sort it All the Tr's that have a ID starting with A should come first and All the Z's should come second.</p> <pre><code>&lt;asp:label id="lblFirstSortOrder" runat="server" style="display:none;"&gt;A,X&lt;/label&gt; &lt;asp:label id="lblSecondSortOrder" runat="server" style="display:none;"&gt;Z,Y&lt;/label&gt; </code></pre> <p>When the page renders..the order should be A_Z,A_Y,X_Z,X_Y</p> <p>Before Rendering this is table that comes from the aspx file:</p> <pre><code>&lt;table&gt; &lt;tr id='Tr_Heading'&gt; &lt;td&gt;A&lt;/td&gt; &lt;td&gt;B&lt;/td&gt; &lt;/tr&gt; &lt;tr id="Tr_X_Y"&gt; &lt;td&gt;GH&lt;/td&gt; &lt;td&gt;GH1&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr_X_Z"&gt; &lt;td&gt;HU&lt;/td&gt; &lt;td&gt;HU1&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr_A_Z"&gt; &lt;td&gt;JI&lt;/td&gt; &lt;td&gt;JI1&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr_A_Y"&gt; &lt;td&gt;JI&lt;/td&gt; &lt;td&gt;JI1&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>Script:</p> <pre><code>function SortAndArrange() { var firstList = document.getElementById('lblFirstSortOrder').value; var secondList = document.getElementById('lblSecondSortOrder').value; var firstTypes = new Array(); firstTypes = firstList.split(','); var secondLists = new Array(); secondLists = secondList.split(','); var refNode = document.getElementById('Tbl_' + firstTypes[0] + "_" + secondTypes[0]); for (var i = 0; i&lt;firstTypes.length; i++) { for (var j = 0; j&lt; secondTypes.length;j++) { var TrName = 'Tbl_'+firstTypes[i]+'_'+secondTypes[j]; var FirstSecondTrs = document.getElementById(TrName); if (FirstSecondTrs) { FirstSecondTrs.parentNode.removeChild(FirstSecondTrs); insertAfter(refNode,FirstSecondTrs); refNode = FirstSecondTrs; } } } } function insertAfter( referenceNode, newNode ) { referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling ); } </code></pre> <p>I hope you guys get the idea.. for me the sorting order will always come from the server and not from the user of the page...</p> <p>Thanks a Lot for all the answers.. Apprecite it. Helped me get to this solution.</p> <p>Thanks, Ben</p>
 

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