Reuse Sorting Function from JQuery DataTables <p>I am using the ENUM sorting routine found at <a href="http://datatables.net/plug-ins/sorting" rel="nofollow">http://datatables.net/plug-ins/sorting</a>. I would like to reuse that same function to sort another list outside of the DataTables plug-in (basically sorting a SELECT element on the same page as the DataTable). I want to avoid having to copy-and-paste (and maintain two sets of business rules) the features of the sort function.</p> <p>For example, if this is the "plug-in" I'm using for DataTables:</p> <pre><code>jQuery.extend(jQuery.fn.dataTableExt.oSort, { "status-enum-pre": function (a) { switch (a) { case "Assigned": return 1; case "Contacted": return 2; case "Meeting Set": return 3; case "Closed": return 4; default: return 5; } }, "status-enum-asc": function (a, b) { return ((a &lt; b) ? -1 : ((a &gt; b) ? 1 : 0)); }, "status-enum-desc": function (a, b) { return ((a &lt; b) ? 1 : ((a &gt; b) ? -1 : 0)); } }); </code></pre> <p>How can I re-use that function to sort the following select list?</p> <pre><code>&lt;select&gt; &lt;option value="Contacted"&gt;Contacted&lt;/option&gt; &lt;option value="Assigned"&gt;Assigned&lt;/option&gt; &lt;option value="Closed"&gt;Closed&lt;/option&gt; &lt;option value="Meeting Set"&gt;Meeting Set&lt;/option&gt; &lt;/select&gt; </code></pre>