Jquery 然而,使用Datatable格式化表并不能对我所有的表都起作用,只能对一个表起作用
我在application.js中有以下内容,我也尝试将其放入prices.coffee.js中 jQuery->Jquery 然而,使用Datatable格式化表并不能对我所有的表都起作用,只能对一个表起作用,jquery,ruby-on-rails,datatable,Jquery,Ruby On Rails,Datatable,我在application.js中有以下内容,我也尝试将其放入prices.coffee.js中 jQuery-> $('#container').dataTable(); 但是,下表不会在DataTable设计中格式化: <h2>Energy Prices</h2> <p id="notice"><%= notice %></p> <table id ="container" class="display"> <
$('#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>
能源价格
身份证件
月
电气
煤气
生物量
不适用
IDs。我想您的问题是有多个表都使用相同的ID。请尝试使用class
或data-*
属性
<table class="container">
$('table.container').dataTable();
$('table.container').dataTable();
或:
$('table[data where=“container”]”)。dataTable();
Hi James感谢您的及时回复。我更改了它,使我的两个表现在都是,并且还将应用程序更改为$('table.container')。dataTable():现在它们都不包含DataTables格式吗?
<table data-whatever="container">
$('table[data-whatever="container"]').dataTable();