Guest User

Untitled

a guest
Nov 12th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <head>
  2.  
  3. <title>jQuery plugin: Tablesorter 2.0</title>
  4.  
  5. <link rel="stylesheet" href="css/jq.css" type="text/css" media="print, projection, screen" />
  6.  
  7. <link rel="stylesheet" href="../themes/blue/style.css" type="text/css" media="print, projection, screen" />
  8.  
  9. <script type="text/javascript" src="../jquery-latest.js"></script>
  10.  
  11. <script type="text/javascript" src="../jquery.tablesorter.js"></script>
  12.  
  13. <script type="text/javascript">
  14.  
  15. $(function() {
  16.  
  17. $(document).ready(function()
  18. {
  19. $("#myTable").tablesorter();
  20. }
  21. );
  22.  
  23.  
  24. });
  25. function append(){
  26. var table = $("#myTable");
  27. $(table).remove();
  28. var tr = $("<tr></tr>");
  29. $("<td></td>").html('Test').appendTo(tr);
  30. $("<td></td>").html('test').appendTo(tr);
  31. $("<td></td>").html('test@gmail.com').appendTo(tr);
  32. $("<td></td>").html('$5.00').appendTo(tr);
  33. $("<td></td>").html('http://www.test.com').appendTo(tr);
  34. $(tr).appendTo(table);
  35. $(table).appendTo($('#tableholer'));
  36. $("#tableholer table").tablesorter();
  37. }
  38.  
  39. </script>
  40.  
  41. </head>
  42. <body>
  43. <div id="tableholer">
  44. <table id="myTable" class="tablesorter">
  45. <thead>
  46. <tr>
  47. <th>Last Name</th>
  48. <th>First Name</th>
  49. <th>Email</th>
  50. <th>Due</th>
  51. <th>Web Site</th>
  52. </tr>
  53. </thead>
  54. <tbody>
  55. <tr>
  56. <td>Smith</td>
  57. <td>John</td>
  58. <td>jsmith@gmail.com</td>
  59. <td>$50.00</td>
  60. <td>http://www.jsmith.com</td>
  61. </tr>
  62. <tr>
  63. <td>Bach</td>
  64. <td>Frank</td>
  65. <td>fbach@yahoo.com</td>
  66. <td>$50.00</td>
  67. <td>http://www.frank.com</td>
  68. </tr>
  69. <tr>
  70. <td>Doe</td>
  71. <td>Jason</td>
  72. <td>jdoe@hotmail.com</td>
  73. <td>$100.00</td>
  74. <td>http://www.jdoe.com</td>
  75. </tr>
  76. <tr>
  77. <td>Conway</td>
  78. <td>Tim</td>
  79. <td>tconway@earthlink.net</td>
  80. <td>$50.00</td>
  81. <td>http://www.timconway.com</td>
  82. </tr>
  83. </tbody>
  84. </table>
  85. </div>
  86. <input type="button" onclick="append()" value="append"/>
  87. </body>
  88.  
  89. var $table = $('table').tablesorter({
  90. theme: 'blue',
  91. widgets: ['zebra', 'columns']
  92. }),
  93. // column index
  94. index = 0,
  95. // column data to add to the table
  96. columns = ['firstName', 'lastName', 'phone|format', 'streetAddress',
  97. 'email', 'city', 'usState|abbr'];
  98.  
  99. $('button').click(function () {
  100. var url = "http://www.filltext.com/?callback=?";
  101. $.getJSON(url, {
  102. 'rows': 10, // number of rows in the table
  103. 'data': '{' + columns[index] + '}'
  104. })
  105. .done(function (data) {
  106. // add new header cell
  107. $table.find('thead tr').append('<th>' + columns[index].split('|')[0] + '</th>');
  108. // increment index to next column
  109. index = (index + 1) % columns.length;
  110. // add new cell to each tbody row
  111. $.each(data, function (i, item) {
  112. var html = "<td>" + item.data + "</td>";
  113. $table.find('tbody tr').eq(i).append(html);
  114. });
  115. // update cache
  116. $table.trigger('updateAll');
  117. });
  118. });
Add Comment
Please, Sign In to add comment