Guest User

Untitled

a guest
Oct 26th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Table Reorder</title>
  6. <script src="jquery-1.7.2.min.js"></script>
  7. <script src="jquery-ui.min.js"></script>
  8. <script src="jquery.dragtable.js"></script>
  9. <link rel="stylesheet" type="text/css" href="dragtable.css" />
  10. </head>
  11. <body>
  12. <table id="tblReg" class="table table-bordered">
  13. <thead>
  14. <tr>
  15. <th>#</th>
  16. <th>First Name</th>
  17. <th>Last Name</th>
  18. <th>Username</th>
  19. <th>Password</th>
  20. <th>Email</th>
  21. <th>Phone</th>
  22. </tr>
  23. </thead>
  24. <tbody class="sort">
  25. <tr>
  26. <th>1</th>
  27. <td>Mark</td>
  28. <td>Otto</td>
  29. <td>@mdo</td>
  30. <td>545trt574</td>
  31. <td>7788994320</td>
  32. </tr>
  33. <tr>
  34. <th>2</th>
  35. <td>Jacob</td>
  36. <td>Thornton</td>
  37. <td>@fat</td>
  38. <td>yffft5456</td>
  39. <td>7788994320</td>
  40. </tr>
  41. <tr>
  42. <th>3</th>
  43. <td>Larry</td>
  44. <td>the Bird</td>
  45. <td>@twitter</td>
  46. <td>fgfhgf444</td>
  47. <td>7788994320</td>
  48. </tr>
  49. <tr>
  50. <th>4</th>
  51. <td>Rima</td>
  52. <td>the Bird</td>
  53. <td>@twitter</td>
  54. <td>jjk8899</td>
  55. <td>7788994320</td>
  56. </tr>
  57. <tr>
  58. <th>5</th>
  59. <td>Sundar</td>
  60. <td>the Bird</td>
  61. <td>@twitter</td>
  62. <td>76767687hjh</td>
  63. <td>7788994320</td>
  64. </tr>
  65. </tbody>
  66. </table>
  67.  
  68. <hr>
  69.  
  70. <table id="tblRegMaster" class="table table-bordered">
  71. <thead>
  72. <tr>
  73. <th>#</th>
  74. <th>First Name</th>
  75. <th>Last Name</th>
  76. <th>Username</th>
  77. <th>Password</th>
  78. <th>Email</th>
  79. <th>Phone</th>
  80. </tr>
  81. </thead>
  82. <tbody class="sort">
  83. <tr>
  84. <th>1</th>
  85. <td>Mark</td>
  86. <td>Otto</td>
  87. <td>@mdo</td>
  88. <td>545trt574</td>
  89. <td>7788994320</td>
  90. </tr>
  91. <tr>
  92. <th>2</th>
  93. <td>Jacob</td>
  94. <td>Thornton</td>
  95. <td>@fat</td>
  96. <td>yffft5456</td>
  97. <td>7788994320</td>
  98. </tr>
  99. <tr>
  100. <th>3</th>
  101. <td>Larry</td>
  102. <td>the Bird</td>
  103. <td>@twitter</td>
  104. <td>fgfhgf444</td>
  105. <td>7788994320</td>
  106. </tr>
  107. <tr>
  108. <th>4</th>
  109. <td>Rima</td>
  110. <td>the Bird</td>
  111. <td>@twitter</td>
  112. <td>jjk8899</td>
  113. <td>7788994320</td>
  114. </tr>
  115. <tr>
  116. <th>5</th>
  117. <td>Sundar</td>
  118. <td>the Bird</td>
  119. <td>@twitter</td>
  120. <td>76767687hjh</td>
  121. <td>7788994320</td>
  122. </tr>
  123. </tbody>
  124. </table>
  125.  
  126. $(document).ready(function(){
  127.  
  128. var tblReg = $('#tblReg').attr('id');
  129. var tblRegMaster = $('#tblRegMaster').attr('id');
  130.  
  131. processDnD(tblReg);
  132. processDnD(tblRegMaster);
  133.  
  134. });
  135.  
  136.  
  137. function processDnD(cuTable){
  138. $('#'+cuTable).find('th').each(function() {
  139. var ctxt = $(this).text();
  140. if(ctxt == 'First Name'){
  141. $(this).attr('id','firstName');
  142. }else if(ctxt == 'Password'){
  143. $(this).attr('id','password');
  144. }else if(ctxt == 'Email'){
  145. $(this).attr('id','iemail');
  146. }else if(ctxt == 'Username'){
  147. $(this).attr('id','Username');
  148. }else if(ctxt == 'Last Name'){
  149. $(this).attr('id','lastName');
  150. }else if(ctxt == '#'){
  151. $(this).attr('id','slNo');
  152. }else if(ctxt == 'Phone'){
  153. $(this).attr('id','phone');
  154. }
  155. })
  156.  
  157. $('#'+cuTable).dragtable({
  158. persistState: function(table) {
  159. if (!window.localStorage) return;
  160. var ss = window.localStorage;
  161. table.el.find('th').each(function(i) {
  162. if(this.id != '') {table.sortOrder[this.id]=i;}
  163. });
  164. ss.setItem('setTableOrder', JSON.stringify(table.sortOrder));
  165. },
  166. restoreState: eval('(' + window.localStorage.getItem('setTableOrder') + ')')
  167. });
  168.  
  169. $('#'+cuTable).each(function(){
  170. $(this).dragtable({
  171. placeholder: 'dragtable-col-placeholder',
  172. items: 'thead th:not(.notdraggable):not(:has(.dragtable-drag-handle)), .dragtable-drag-handle',
  173. appendTarget: $(this).parent(),
  174. scroll: true
  175. })
  176. });
  177. }
Advertisement
Add Comment
Please, Sign In to add comment