【发布时间】:2017-12-11 23:17:26
【问题描述】:
我有一个与 will_paginate 一起使用的基本数据表。
<table id="users" class="display" data-source="<%= url_for(:controller => "/account", :action => :paginate, :format => :json) %>">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Role</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
jQuery 是
<script type="text/javascript">
jQuery(function() {
return $('#users').DataTable({
processing: true,
serverSide: true,
ajax: $('#users').data('source'),
columns : [
{ data: "first_name" },
{ data: "last_name" },
{ data: "username" },
{ data: "role" }
]
});
});
</script>
虽然大部分工作都非常好,包括列搜索,但我的角色列却没有。
虽然其他所有内容都是我使用 SQL 查询的属性,但角色是一个方法调用。
def role
return "admin" if self.admin?
return "manager" if self.manager?
return "user"
end
这反过来不适用于列排序。
话虽如此,有没有办法将 will_paginate 和 datatables 与 ajax 一起使用来使用方法输出的自定义排序?我尝试在列上使用data-order,但似乎不是这样。
【问题讨论】:
标签: jquery ruby-on-rails ajax datatables will-paginate