Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. $table = $('#KiList').dataTable({
  2. bAutoWidth: false,
  3. aoColumns: [{
  4. 'sWidth': '35%'
  5. }, {
  6. 'sWidth': '20%',
  7. "sType": "datetime-us"
  8. }, {
  9. 'sWidth': '25%',
  10. "sType": 'string'
  11. }, {
  12. 'sWidth': '10%',
  13. "sType": 'string'
  14. }, {
  15. 'sWidth': '10%',
  16. "sType": 'string'
  17. }],
  18. "aoColumnDefs": [{
  19. "aTargets": [1],
  20. "mRender": function(date, type, full) {
  21. return moment(date).format('MM-DD-YYYY hh:mm a');
  22. }
  23. }],
  24. aaSorting: [[1, 'desc']]
  25. });
  26.  
  27. $table = $('#KiList').dataTable({
  28. bAutoWidth: false,
  29. aoColumns: [{
  30. 'sWidth': '35%'
  31. }, {
  32. 'sWidth': '20%',
  33. "type": "datetime-us"//changed
  34. }, {
  35. 'sWidth': '25%',
  36. "sType": 'string'
  37. }, {
  38. 'sWidth': '10%',
  39. "sType": 'string'
  40. }, {
  41. 'sWidth': '10%',
  42. "sType": 'string'
  43. }],
  44. "aoColumnDefs": [{
  45. "aTargets": [1],
  46. "mRender": function(date, type, full) {
  47. return moment(date).format('MM-DD-YYYY hh:mm a');
  48. }
  49. }],
  50. aaSorting: [[1, 'desc']]
  51. });
  52.  
  53. jQuery.extend( jQuery.fn.dataTableExt.oSort, {
  54. "datetime-us": function ( a ) {
  55. // If there's no slash, then it's not an actual date, so return zero for sorting
  56. if(a.indexOf('/') === -1) {
  57. return '0';
  58. } else {
  59. // Set optional items to zero
  60. var hour = 0,
  61. min = 0,
  62. ap = 0;
  63. // Execute match. Requires month, day, year. Can be mm/dd or m/d. Can be yy or yyyy
  64. // Time is optional. am/pm is optional
  65. // TODO - remove extra time column from array
  66. var b = a.match(/(d{1,2})/(d{1,2})/(d{2,4})( (d{1,2}):(d{1,2}))? ?(am|pm|AM|PM|Am|Pm)?/),
  67. month = b[1],
  68. day = b[2],
  69. year = b[3];
  70. // If time exists then output hours and minutes
  71. if (b[4] != undefined) {
  72. hour = b[5];
  73. min = b[6];
  74. }
  75. // if using am/pm then change the hour to 24 hour format for sorting
  76. if (b[7] != undefined) {
  77. ap = b[7];
  78. if(hour == '12') hour = '0';
  79. if(ap == 'pm') hour = parseInt(hour, 10)+12;
  80. }
  81.  
  82. // for 2 digit years, changes to 20__ if less than 70
  83. if(year.length == 2){
  84. if(parseInt(year, 10) < 70) year = '20'+year;
  85. else year = '19'+year;
  86. }
  87. // Converts single digits
  88. if(month.length == 1) month = '0'+month;
  89. if(day.length == 1) day = '0'+day;
  90. if(hour.length == 1) hour = '0'+hour;
  91. if(min.length == 1) min = '0'+min;
  92. var tt = year+month+day+hour+min;
  93.  
  94. return tt;
  95. }
  96. },
  97. "datetime-us-asc": function ( a, b ) {
  98. return a - b;
  99. },
  100. "datetime-us-desc": function ( a, b ) {
  101. return b - a;
  102. }
  103. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement