1
0

yarn.dt.plugins.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. if (!jQuery.fn.dataTableExt.fnVersionCheck("1.7.5")) {
  2. alert("These plugins requires dataTables 1.7.5+");
  3. }
  4. // don't filter on hidden html elements for an sType of title-numeric
  5. $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) {
  6. return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
  7. }
  8. // 'title-numeric' sort type
  9. jQuery.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) {
  10. var x = a.match(/title=["']?(-?\d+\.?\d*)/)[1];
  11. var y = b.match(/title=["']?(-?\d+\.?\d*)/)[1];
  12. x = parseFloat( x );
  13. y = parseFloat( y );
  14. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  15. };
  16. jQuery.fn.dataTableExt.oSort['title-numeric-desc'] = function(a,b) {
  17. var x = a.match(/title=["']?(-?\d+\.?\d*)/)[1];
  18. var y = b.match(/title=["']?(-?\d+\.?\d*)/)[1];
  19. x = parseFloat( x );
  20. y = parseFloat( y );
  21. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  22. };
  23. jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
  24. var
  25. _that = this,
  26. iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
  27. this.each( function ( i ) {
  28. $.fn.dataTableExt.iApiIndex = i;
  29. var
  30. $this = this,
  31. oTimerId = null,
  32. sPreviousSearch = null,
  33. anControl = $( 'input', _that.fnSettings().aanFeatures.f );
  34. anControl.unbind( 'keyup' ).bind( 'keyup', function() {
  35. var $$this = $this;
  36. if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
  37. window.clearTimeout(oTimerId);
  38. sPreviousSearch = anControl.val();
  39. oSettings.oApi._fnProcessingDisplay(oSettings, true);
  40. oTimerId = window.setTimeout(function() {
  41. $.fn.dataTableExt.iApiIndex = i;
  42. _that.fnFilter( anControl.val() );
  43. oSettings.oApi._fnProcessingDisplay(oSettings, false);
  44. }, iDelay);
  45. }
  46. });
  47. return this;
  48. } );
  49. return this;
  50. }
  51. function renderHadoopDate(data, type, full) {
  52. if (type === 'display') {
  53. if(data === '0') {
  54. return "N/A";
  55. }
  56. return new Date(parseInt(data)).toUTCString();
  57. }
  58. // 'filter', 'sort', 'type' and undefined all just use the number
  59. // If date is 0, then for purposes of sorting it should be consider max_int
  60. return data === '0' ? '9007199254740992' : data;
  61. }
  62. function renderHadoopElapsedTime(data, type, full) {
  63. if (type === 'display') {
  64. var timeDiff = parseInt(data);
  65. if(timeDiff < 0)
  66. return "N/A";
  67. var hours = Math.floor(timeDiff / (60*60*1000));
  68. var rem = (timeDiff % (60*60*1000));
  69. var minutes = Math.floor(rem / (60*1000));
  70. rem = rem % (60*1000);
  71. var seconds = Math.floor(rem / 1000);
  72. var toReturn = "";
  73. if (hours != 0){
  74. toReturn += hours;
  75. toReturn += "hrs, ";
  76. }
  77. if (minutes != 0){
  78. toReturn += minutes;
  79. toReturn += "mins, ";
  80. }
  81. toReturn += seconds;
  82. toReturn += "sec";
  83. return toReturn;
  84. }
  85. // 'filter', 'sort', 'type' and undefined all just use the number
  86. return data;
  87. }
  88. function parseHadoopID(data, type, full) {
  89. if (type === 'display' || type === 'filter') {
  90. return data;
  91. }
  92. //Parse the ID for 'sort', 'type' and undefined
  93. //The number after the last '_' and before the end tag '<'
  94. var splits = data.split('_');
  95. return splits[parseInt(splits.length-1)].split('<')[0];
  96. }
  97. function parseHadoopProgress(data, type, full) {
  98. if (type === 'display') {
  99. return data;
  100. }
  101. //Return the title attribute for 'sort', 'filter', 'type' and undefined
  102. return data.split("'")[1];
  103. }