【发布时间】:2015-07-17 20:01:53
【问题描述】:
编辑:如果可能的话,我更愿意使用引导程序来实现此功能,因为我的项目中有引导程序。看来我可能只是缺少在我的 rails 项目中利用 bootstrap 的 javascript 的东西。
单击列名时,表格应按该列名对数据进行排序。下表是:
我尝试按照at this website 显示的示例使用引导程序对数据进行排序,但它对我不起作用。我错过了什么?
我的 Gemfile 中的相关宝石:
#Gemfile
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
CSS:
#app/assets/stylesheets/application.css.scss
@import "bootstrap-sprockets";
@import "bootstrap";
/*
*= require_tree .
*= require_self
*/
Javascript:
#app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .
查看显示记录:
#app/views/index.html.erb
<h4>Listing Users</h4>
<table class=" table table-striped" data-sort-name="name" data-sort-order="desc">
<thead>
<tr>
<th data-field="name" data-sortable="true">Name</th>
<th data-field="age" data-sortable="true">Age</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.age %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New User', new_user_path %>
【问题讨论】:
-
示例显示
data-sortable="true"被赋予<th>。尝试在您的代码中为<th>提供data-sortable="true",并为<td>删除它。 -
@Pavan 在将代码移到堆栈溢出时是一个拼写错误。不幸的是,它仍然不适合我。
-
尝试将
//= require jquery-ui/sortable添加到您的apllication.js -
@Pavan 我尝试安装
jquery-ui-railsgem 并在 javascript 和 css 文件中添加 jquery-ui 的东西,但仍然没有工作。
标签: ruby-on-rails ruby twitter-bootstrap