[英]Rails 5.2 Datatables will not Refresh Data on Page Change
I have a rails 5.2 project that has datatables configured. 我有一个配置了数据表的rails 5.2项目。 The plugin works fine but if I change a page then hit the back button the data in the table does not load again with datatables. 该插件工作正常但如果我更改页面然后点击后退按钮,表中的数据不会再次加载数据表。 It says "No data in table". 它说“表格中没有数据”。 It sounds like a turbolinks issue to me. 这对我来说听起来像是一个涡轮问题。
I am using the following to generate the table: 我使用以下来生成表:
$( document ).on('turbolinks:load', function() {
$("#prjtbl").dataTable();
});
The datatables plugin loads between page changes but the data in the table does not refresh. datatables插件在页面更改之间加载,但表中的数据不会刷新。 Any ideas on how to fix this? 有想法该怎么解决这个吗?
UPDATE: Application.js 更新:Application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require jquery
//= require datatables
//= require popper
//= require bootstrap-sprockets
//= require shards-dashboards
//= require trix
//= require activestorage
//= require turbolinks
//= require_tree .
Page.js Page.js
JQuery(function() {
$( document ).on('turbolinks:load', function() {
$("#prjtbl").dataTable();
});
});
document.addEventListener("turbolinks:load", function() {
"use strict";
if ($("#prjtbl").length == 0) {
$("#prjtbl").dataTable();
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.