Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. $(document).ready(function()
  2. {
  3. $("#myTable").tablesorter();
  4. setHeightByAttr('Sum');
  5. }
  6. );
  7.  
  8. function setAllSameHeight()
  9. {
  10. var t = document.getElementById("myTable");
  11. for(var i=0; i<t.rows.length; i++){
  12. t.rows[i].style.height = "30px";
  13. }
  14.  
  15. }
  16.  
  17. function setHeightByAttr(attr)
  18. {
  19. //find the index of the attribute and save it in a variable called index
  20.  
  21.  
  22.  
  23. setTimeout(function() {
  24. var index = null;
  25. var t = document.getElementById("myTable");
  26. for(var i = 0; i < t.rows[0].cells.length; i++){
  27. if(t.rows[0].cells[i].innerText == attr+"n"){
  28. index = i;
  29. break
  30. }
  31. }
  32. t.rows[1].style.height = "30px";
  33. for(var i=2; i < t.rows.length; i++) {
  34. var sumi = t.rows[i].cells[index].innerHTML;
  35. var sumiminus1 = t.rows[i-1].cells[index].innerHTML;
  36. t.rows[i].style.height = 30+30*(Math.abs(sumi-sumiminus1)).toString()+"px";
  37.  
  38. }
  39. }, 5);
  40. }
  41.  
  42. <div class="container">
  43. <div class="row">
  44. <h5>The Ranklist is last updated at {{$update}}</h5>
  45. </div>
  46. <div class="row">
  47. <div class="col-xs-12">
  48. <table id="myTable" class="table table-condensed tablesorter">
  49. <thead>
  50. <tr>
  51. <th class="rank">R</th>
  52. <th class="hidden-xs flag" onclick= "setAllSameHeight()">Flag</th>
  53. <th onclick="setAllSameHeight()">Name</th>
  54. <th class="hidden-xs sortInitialOrder-desc" onclick= "setHeightByAttr('MC')">MC</th>
  55. <th class="hidden-xs sortInitialOrder-desc" onclick= "setHeightByAttr('TC')">TC</th>
  56. <th class="sortInitialOrder-desc" onclick="setHeightByAttr('SPE')">SPE</th>
  57. <th class="hidden-xs sortInitialOrder-desc" onclick= "setHeightByAttr('HW')">HW</th>
  58. <th class="hidden-xs sortInitialOrder-desc" onclick= "setHeightByAttr('Bs')">Bs</th>
  59. <th class="hidden-xs sortInitialOrder-desc" onclick= "setHeightByAttr('KS')">KS</th>
  60. <th class="hidden-xs sortInitialOrder-desc" onclick= "setHeightByAttr('Ac')">Ac</th>
  61. <th class="sortInitialOrder-desc" onclick="setHeightByAttr('DIL')">DIL</th>
  62. <th class="sortInitialOrder-desc" onclick="setHeightByAttr('Sum')">Sum</th>
  63. </tr>
  64. </thead>
  65. </table>
  66. </div>
  67. </div>
  68. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement