[英]Rails dataTables have to reload page
I'm using dataTables in a Rails app. 我在Rails应用程序中使用dataTables。 I have a model called
site
. 我有一个名为
site
的模型。
The index for site
uses a dataTable to list the sites. site
索引使用dataTable列出站点。
When I first load the index page 当我第一次加载索引页面时
http://localhost:3000/sites
The dataTable doesn't work. dataTable不起作用。 There are no console errors.
没有控制台错误。
If I reload the page, it works! 如果我重新加载页面,它将起作用!
During the reload, the console shows entries like this: 在重新加载期间,控制台显示如下条目:
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/bootstrap.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/bootstrap-editable.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/ColVis.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/datetimepicker.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/datepicker.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/dataTables/bootstrap/3/jquery.dataTables.bootstrap.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/jquery.qtip.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/jquery.treeTable.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/TableTools.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/TableTools_JUI.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
...
Thanks for the help! 谢谢您的帮助!
Do you use gem turbolink ? 您是否使用gem turbolink ? If yes, that can be the reason of it, because it do not reload the whole page, just partially.
如果是,那可能是它的原因,因为它不会重新加载整个页面,只是部分重新加载。 You can solve it in two different ways:
您可以通过两种不同的方式解决它:
Move your datatable init code into page:change , like this in application.js: 将您的数据表初始化代码移动到page:change中 ,就像在application.js中一样:
$(document).on("page:change", function() { $('#yourtable').dataTable(); }); $(document).on(“ page:change”,function(){$('#yourtable')。dataTable();});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.