title: Natural Sorting Datatable.js
body: <p>Natural sorting in datatable.js</p>
  
  <p>Using this javascript fuctionnaturalSort(a, b) we can any datatype column sorting</p>
  
  <p>Example: we want sorting is datatable like 1,101,99,88,103</p>
  
  <p>We can use this and result will be 1,88,99,101,103</p>
  
  <pre><code>        function naturalSort(a, b) {
  
              // setup temp-scope variables for comparison evauluation
  
              var x = a.toString().toLowerCase() || '', y = b.toString().toLowerCase() || '',
              nC = String.fromCharCode(0),
              xN = x.replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC),
              yN = y.replace(/([-]{0,1}[0-9.]{1,})/g, nC + '$1' + nC).split(nC),
              xD = (new Date(x)).getTime(), yD = (new Date(y)).getTime();
  
              // natural sorting of dates
  
              if (xD &amp;&amp; yD &amp;&amp; xD &lt; yD)
                  return -1;
              else if (xD &amp;&amp; yD &amp;&amp; xD &gt; yD)
                  return 1;
  
              // natural sorting through split numeric strings and default strings
              for (var cLoc = 0, numS = Math.max(xN.length, yN.length) ; cLoc &lt; numS; cLoc++)
                  if ((parseFloat(xN[cLoc]) || xN[cLoc]) &lt; (parseFloat(yN[cLoc]) || yN[cLoc]))
                      return -1;
                  else if ((parseFloat(xN[cLoc]) || xN[cLoc]) &gt; (parseFloat(yN[cLoc]) || yN[cLoc]))
                      return 1;
              return 0;
          }
  
          jQuery.fn.dataTableExt.oSort['natural-asc'] = function (a, b) {
              return naturalSort(a, b);
          };
  
          jQuery.fn.dataTableExt.oSort['natural-desc'] = function (a, b) {
             return naturalSort(a, b) * -1;
          };
  </code></pre>
  
  <p>Add aocolumns in datatable properties and put sType is natual.      </p>
  
  <pre><code>       aoColumns: [
              { "sType": "natural" }
          ],
  </code></pre>