JSFiddle - React, Tailwind, and code Playground

by jordan_josh3184

HTML

<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<table id="example" class="display" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>Name</th>
      <th>Position</th>
      <th>Office</th>
      <th>Age</th>
      <th>Salary</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <th>Name</th>
      <th>Position</th>
      <th>Office</th>
      <th>Age</th>
      <th>Salary</th>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>Tiger Nixon</td>
      <td>System Architect</td>
      <td>Edinburgh</td>
      <td></td>
      <td>$320,800</td>
    </tr>
     <tr>
      <td>James Nixon</td>
      <td>System Architect</td>
      <td>Edinburgh</td>
      <td></td>
      <td>$320,800</td>
    </tr>
    <tr>
      <td>Garrett Winters</td>
      <td>Accountant</td>
      <td>Tokyo</td>
      <td>63</td>
      <td></td>
    </tr>
    <tr>
      <td>Cedric Kelly</td>
      <td>Senior Javascript Developer</td>
      <td>Edinburgh</td>
      <td>22</td>
      <td>$433,060</td>
    </tr>
    <tr>
      <td>Airi Satou</td>
      <td>Accountant</td>
      <td>Tokyo</td>
      <td></td>
      <td>$162,700</td>
    </tr>
    <tr>
      <td>Brielle Williamson</td>
      <td>Integration Specialist</td>
      <td>New York</td>
      <td>61</td>
      <td></td>
    </tr>
    <tr>
      <td>Herrod Chandler</td>
      <td>Sales Assistant</td>
      <td>San Francisco</td>
      <td>59</td>
      <td>$137,500</td>
    </tr>
    <tr>
      <td>Rhona Davidson</td>
      <td>Integration Specialist</td>
      <td>Tokyo</td>
      <td>55</td>
      <td>$327,900</td>
    </tr>
    <tr>
      <td>Colleen Hurst</td>
      <td>Javascript Developer</td>
      <td>San Francisco</td>
      <td>39</td>
      <td>$205,500</td>
    </tr>
    <tr>
      <td>Sonya Frost</td>
      <td>Software...

JavaScript

$(document).ready(function() {
$.fn.dataTable.ext.errMode = 'none';	// stop pop-up alerts from datatable errors.
	
	
	$.fn.dataTable.ext.oSort['nullsort-asc']  = function(a,b) {
        console.log("asc val of:" + a + ":val of y:" + b);
		  //return sortNumbersIgnoreText(a, b, Number.POSITIVE_INFINITY);
    const isNumA = !isNaN(a);//check if a is a number
 const isNumB = !isNaN(b);//check if b is a number

 if(!a && !b){return 0;}//if both are null return 0; don't need to change order
 else if(!a){return 1;}//if a is null and b isn't return 1
 else if(!b){return -1;} //if b is null and a isn't return -1
 else if(isNumA && isNumB){return Number(a) - Number(b);}//if they are both numbers do a number sort
 else if(isNumA){return -1;}//if a is a number and b isn't return 1
 else if(isNumB){return 1;}//if b is a number and a isn't return -1
 else {return (a).localeCompare(b);//neither are number and neither are null, do a standard string sort
}
    };
    $.fn.dataTable.ext.oSort['nullsort-desc']  = function(a,b) {
    if(a == "")
            return 1;
        if(b == "")
            return -1;
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    // return sortNumbersIgnoreText(a, b, Number.NEGATIVE_INFINITY) * -1;
    };

    $('#example').DataTable({
    	//"aaSorting": [[3,'asc']],
      columnDefs: getColumnDef()
    });
} );

/*function sortNumbersIgnoreText(a, b, high) {
    //var reg = /[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?[0-9]+)?/;    
    a = a.replace(/,/g, '');
    //a = a.match(reg);      
    a = a !== null ? parseFloat(a[0]) : high;
    b = b.replace(/,/g, '');
    //b = b.match(reg);    
    b = b !== null ? parseFloat(b[0]) : high;
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));    
}*/

function getColumnDef(){
		  return [
		       
			 { type: 'nullsort', targets: 3 },
			 { type: 'nullsort', targets: 4}
			
		    ];
}