2013-03-06 20 views
0

我有application.js中內以下,我也試着將它放在prices.coffee.js使用數據表格式表,但是,它不會爲我所有的工作表只有一個

jQuery的 - >

$('#container').dataTable(); 

然而,下表將不會在數據表設計格式:

<h2>Energy Prices</h2> 

<p id="notice"><%= notice %></p> 

<table id ="container" class="display"> 
<thead> 
<tr> 
    <th>ID</th> 
    <th>Month</th> 
    <th>Elec</th> 
    <th>Gas</th> 
    <th>Biomass</th> 
</tr> 
</thead> 
<tbody> 
<% @usages.each do |usage| %> 
<tr> 
    <td><%= usage.price.usage_id %></td> 
    <td><%= usage.month.strftime("%b %Y") %></td> 
    <% usage.price.attributes.each do |k,v| %> 
     <% if v.nil? %> 
      <td>N/A</td> 
     <% elsif k != "created_at" && k != "updated_at" && k != "month" && k != "id" && k != "usage_id" %> 
      <td><%= v %></td> 
     <% end %> 
    <% end %> 
    <td><%= link_to "Edit", edit_price_path(usage) %> </td> 
</tr> 
<% end %> 
</tbody> 
</table> 

回答

0

標識may only be used once per page。我想你的問題是你有多個表都使用相同的ID。嘗試使用classdata-*屬性代替。

<table class="container"> 
$('table.container').dataTable(); 

或者:

<table data-whatever="container"> 
$('table[data-whatever="container"]').dataTable(); 
+0

嗨詹姆斯感謝您的及時答覆。我改變了它,以便我的兩個表現在是

,並將應用程序更改爲$('table.container')。dataTable():現在它們都不包含DataTables格式? – user20554502013-03-06 14:50:24

相關問題