0

我在 application.js 中有以下内容,我也尝试将其放入 price.coffee.js

jQuery->

$('#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>
4

1 回答 1

0

每页只能使用一次ID 。我想您的问题是您有多个表都使用相同的 ID。尝试使用classordata-*属性。

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

或者:

<table data-whatever="container">
$('table[data-whatever="container"]').dataTable();
于 2013-03-06T12:11:00.170 回答