gpt4 book ai didi

javascript - 脚踏式分页不适用于动态数据 Rails

转载 作者:行者123 更新时间:2023-11-28 06:28:17 26 4
gpt4 key购买 nike

我正在尝试在我的 Rails 应用程序中使用 footable。但我无法使用动态表数据实现分页。

这是我的代码

<table class="footable table table-stripped" data-page-size="10" data-filter=#filter>
<thead>
<tr>
<th>Organization Name</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<%@organizations.each do |org|%>
<tr class="gradeX">
<td><%=org.name%></td>
<td><%=org.type%></td>
</tr>
<%end%>
</tbody>
<tfoot>
<tr>
<td colspan="5">
<ul class="pagination pull-right">
<%=paginate @organizations%>
</ul>
</td>
</tr>
</tfoot>
</table>
<script type="text/javascript">

$(function() {
alert(); //testing
$('.footable').footable();

});

</script>

但是它只显示 10 条记录,尽管它在表中最多包含 45 条记录(即使更改数据页大小也最多显示 10 条记录)。

如果有人发现这个问题,请帮助我,谢谢。

最佳答案

不确定您是否仍然遇到这个问题,但我偶然发现了这个问题,所以我想我会回答它。

发生这种情况的原因是,您正在对已经通过 Rails gem 分页的记录调用 Footable 的 Paging Component(通过使用

来指示)
...
<ul class="pagination pull-right">
<%=paginate @organizations%>
</ul>
...

因此,Footable 仅由您的 Rails 应用程序提供 10 条记录,然后尝试对这些记录进行分页。本质上,您是在对一组数据进行“双分页”。

Footable V3 中,现在的语法是:

通过 HTML 数据属性调用

<table class="footable table table-stripped" ... data-paging="true" data-paging-size="15" ... >

通过JS调用

$('.footable').footable({
"paging": {
"enabled": true,
"limit": 10
}
});

引用Footable Paging Docs了解更多信息。

因此,本质上,请选择 Rails PaginateFootable Paging,但不能同时选择两者。希望这会有所帮助。

关于javascript - 脚踏式分页不适用于动态数据 Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34920425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com