× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to sort a jQuery DataTable on columns containing UK format date

Dominic Myers
Oct 09, 2014
<p>I've used all sorts of methods to do this but now simply include the brilliant <a href="http://momentjs.com/">Moment.js</a> library and get that to do the heavy lifting using:</p><pre><code class="language-javascript">$.extend( jQuery.fn.dataTableExt.oSort, { "date-uk-pre": function (a){ return parseInt(moment(a, "DD/MM/YYYY").format("X"), 10); }, "date-uk-asc": function (a, b) { return a - b; }, "date-uk-desc": function (a, b) { return b - a; } });</code></pre><p>IMPORTANT: Remember to set the column type as <code class="language-javascript">date-uk<code>.</code></code></p>
comments powered by Disqus