2013-03-06 2 views
0

나는이 (가) application.js에서 다음을 가지고 있고 나는 또한 jQuery를 prices.coffee.js하나의

퍼팅 시도했습니다 - >

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

그러나, 다음 표는 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

ID를 may only be used once per page. 귀하의 문제는 당신이 동일한 ID를 사용하여 여러 개의 테이블을 가지고 있다고 상상해보십시오. 대신 class 또는 data-* 속성을 사용해보세요.

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

또는 : 프롬프트 응답에 대한

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

하이 제임스 감사합니다. 두 테이블이 이제

가되도록 응용 프로그램을 $ ('table.container')로 변경했습니다. dataTable() : 이제는 DataTables 형식이 포함되어 있지 않습니다. – user2055450

관련 문제