Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on Lekensteyn's excellent response, I've developed the following solution to my needs. I haven't done full QA testing on it yet and don't know if it is perfect (in fact, I'm quite sure it's not), but I hope that others can get some use out of this and build upon it for their needs. I'll post an update if any major changes needed made.</p> <pre><code>function do2DArraySort(dataArr, orderList, orderDir) { for (x=orderList.length-1; x &gt;= 0; x--) { if (orderDir[x] == 'asc') { dataArr.sort(sortMethodFunctionAsc); } else { dataArr.sort(sortMethodFunctionDesc); } } return dataArr; } function sortMethodFunctionAsc(a, b) { if ((IsNumeric(a[orderList[x]]) &amp;&amp; IsNumeric(b[orderList[x]])) || (IsDate(a[orderList[x]]) &amp;&amp; IsDate(b[orderList[x]]))) { return a[orderList[x]] - b[orderList[x]]; } else { if (a[orderList[x]].toString() &gt; b[orderList[x]].toString()) { return 1; } else if (a[orderList[x]].toString() &lt; b[orderList[x]].toString()) { return -1; } else { return 0; } } } function sortMethodFunctionDesc(a, b) { if ((IsNumeric(a[orderList[x]]) &amp;&amp; IsNumeric(b[orderList[x]])) || (IsDate(a[orderList[x]]) &amp;&amp; IsDate(b[orderList[x]]))) { return b[orderList[x]] - a[orderList[x]]; } else { if (a[orderList[x]].toString() &lt; b[orderList[x]].toString()) { return 1; } else if (a[orderList[x]].toString() &gt; b[orderList[x]].toString()) { return -1; } else { return 0; } } } function IsNumeric(input) { return (input - 0) == input &amp;&amp; input.length &gt; 0; } function IsDate(testValue) { var returnValue = false; var testDate; try { testDate = new Date(testValue); if (!isNaN(testDate)) { returnValue = true; } else { returnValue = false; } } catch (e) { returnValue = false; } return returnValue; } </code></pre>
    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.
    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