Ich benutze Ruby on Rails und habe eine Tabelle, die ich sortieren möchte. Das Tablesorter jquery Plugin und es ist richtig in meine Dateien geladen. Ich habe jquery davor gut genannt. Ich habe diesen Code in meinem Javascript.Jquery Tablesorter in Rubin auf Schienen
$(document).ready(function(){
$("#myTable").tablesorter({widgets: ['zebra']});
$("#business").tablesorter({sortList: [[0,0], [1,0]]});
});
Ich habe 2 Tabellen. Ich habe meine Tabelle, die statisch ist, nur um zu sehen, ob der Code richtig funktioniert (und es tut). Ich kann sortieren, indem ich auf einen der Header klicke.
<table id="myTable">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Email</th>
<th>Due</th>
<th>Web Site</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td>
<td>John</td>
<td>[email protected]</td>
<td>$50.00</td>
<td>http://www.jsmith.com</td>
</tr>
<tr>
<td>Bach</td>
<td>Frank</td>
<td>[email protected]</td>
<td>$50.00</td>
<td>http://www.frank.com</td>
</tr>
<tr>
<td>Doe</td>
<td>Jason</td>
<td>[email protected]</td>
<td>$100.00</td>
<td>http://www.jdoe.com</td>
</tr>
<tr>
<td>Conway</td>
<td>Tim</td>
<td>tc[email protected]</td>
<td>$50.00</td>
<td>http://www.timconway.com</td>
</tr>
</tbody>
</table>
Aber ich habe auch meine andere Tabelle, die dynamisch aus einer Datenbank zieht. Was überhaupt nicht funktioniert und überhaupt nichts macht, wenn ich auf die Header klicke.
<table width="650" cellpadding="6" cellspacing="0" id="business">
<thead>
<tr>
<th>Business Name</th>
<th>Address</th>
<th>Category</th>
<th>Description</th>
</tr>
</thead>
<% @businesses.each do |business|if !business.approved %>
<tbody>
<tr>
<td><a class="Contact<%=h business.id %>" href="#"><%=h business.name %></a></td>
<td><%=h business.address %></td>
<td><%=h business.business_category.name %></td>
<td><%=h business.description %></td>
</tr>
</tbody>
<% end %>
</table>
Jede Hilfe wäre großartig.
Haben Sie das jemals gelöst? – Dsel
Bitte zurück, was funktioniert hat. – DDDD