3

我有我的Rails應用程序中的表與數據表一起工作,但在安裝引導程序並嘗試使用引導設置表後,表將不會切換到新的樣式。我按照「Twitter Bootstrap 3安裝」中列出的步驟操作:https://github.com/rweng/jquery-datatables-railsRails dataTable引導樣式不工作

不知道我在做什麼錯。這裏是我的代碼:

表鑑於:

<table id="products"> 
    <thead> 
     <tr> 
     <th>Name</th> 
     <th>Price</th> 
     </tr> 
    </thead> 

    <tbody> 
     <tr> 
      <td>Something</td> 
      <td>Something</td> 
     </tr> 
     <tr> 
      <td>Something</td> 
      <td>Something</td> 
     </tr> 
     <tr> 
      <td>Something</td> 
      <td>Something</td> 
     </tr> 
    </tbody> 
</table> 

的application.js

//= require jquery 
//= require jquery_ujs 
//= require twitter/bootstrap 
//= require dataTables/jquery.dataTables 
//= require dataTables/jquery.dataTables.bootstrap3 
//= require turbolinks 
//= require_tree . 

$(document).ready(function() 
    { 
     $("#products").dataTable({ 
      sPaginationType: "bootstrap" 
     }); 
    } 
); 

Application.css

/* 
*= require_self 
*= require dataTables/jquery.dataTables.bootstrap3 
*= require_tree . 
*/ 

我做錯了什麼?謝謝你的幫助。

UPDATE

我加類=「表表邊框的表格條紋」這幫助了一點,但仍然沒有做的工作。

回答

1

我不得不創業板直接通過github上鍊接,否則就只能用引導3(這是Rails 4應用,但也能在Rails的3.2)風格的分頁。

gem 'jquery-datatables-rails', git: 'git://github.com/rweng/jquery-datatables-rails.git' 

我的應用程序/資產/ Java腳本/ application.js中

//= require jquery 
//= require jquery_ujs 
//= require turbolinks 
//= require dataTables/jquery.dataTables 
//= require dataTables/jquery.dataTables.bootstrap3 
//= require_tree . 

我的應用程序/資產/樣式表/ application.css

/* 
*= require dataTables/jquery.dataTables 
*= require dataTables/jquery.dataTables.bootstrap3 
*= require_tree . 
*= require_self 
*/ 

我的應用程序/資產/ Java腳本/產品。 js.coffee

jQuery -> 
    $('#datatable_products').dataTable 
    sPaginationType: "bootstrap" 

我的a PP /視圖/產品/ index.html.erb

<table id="datatable_products" class="table table-striped"> 
<thead> 
    <tr> 
    <th>Name</th> 
    <th>Category</th> 
    <th>Price</th> 
    <th>Stock</th> 
    <th></th> 
    <th></th> 
    <th></th> 
    </tr> 
</thead> 

<tbody> 
    <% @products.each do |product| %> 
    <tr> 
     <td><%= product.name %></td> 
     <td><%= product.category %></td> 
     <td><%= product.price %></td> 
     <td><%= product.stock %></td> 
     <td><%= link_to 'Show', product %></td> 
     <td><%= link_to 'Edit', edit_product_path(product) %></td> 
     <td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %> </td> 
    </tr> 
    <% end %> 
</tbody> 
</table> 

小心,你有在THEAD和TBODY標籤右邊的數字。另外,導軌4中的三個空元素的快捷方式與

<th colspan="3"></th> 

將導致未初始化的數據表。

如果你需要一個例子或幫助,來看看:
https://github.com/emilde92/datatablestore
http://www.datatables.net/manual/styling/bootstrap
http://getbootstrap.com/css/
http://railscasts.com/episodes/340-datatables