DataTables切换分页跳转回首页问题求助
DataTables分页跳转回首页问题求助
- 切换DataTables分页时会自动跳回首页,之前用以下定时刷新代码解决过同类问题,但本次无效:
setTimeout(function() { datatable_FTP.ajax.reload(null, false); }, 30000);
当前使用的相关代码如下:
function modalTable_WEBAPI_alarm() { const getToken = localStorage.getItem("token"); var getData; var currentPage = 1; var datatable_WEBAPI_alarm = $("#id_datatable_WEBAPI_alarm").DataTable({ ajax: { url: "http://192.168.10.01:1000/api/message/all_item", // Fake API headers: { 'Authorization': 'Bearer ' + getToken }, dataSrc: function (response) { console.log("DATA MODAL TABLE", response.data); getData = response.data.map(obj => { let result = JSON.parse(JSON.stringify(obj)); result['isChanged'] = false; // Assign a variable return result; }); return getData; }, }, destroy: true, columns: [ { data: "sf", title: "sf" }, { data: "code", title: "code" }, { data: "subcode", title: "subcode" }, { data: "msgtext", title: "msgtext" }, { data: "description", title: "description_webapi_alarm" }, { data: null, title: "Alarm/Event Setting", render: function (data, type, row) { var switchId = 'customSwitch_' + row.id; // Assuming you have an 'id' field in your data var switchHTML = '<div class="custom-control custom-switch">'; var isChecked = row.webapi ? 'checked' : ''; // Check if rowData.webapi is true, if so, add the checked attribute switchHTML += '<input type="checkbox" class="custom-control-input" id="webapi_' + switchId + '" ' + isChecked + '>'; switchHTML += '<label class="custom-control-label" for="webapi_' + switchId + '">Selected_webapi</label>'; switchHTML += '</div>'; return switchHTML; }, createdCell: function (td, cellData, rowData, row, col) { var switchId = 'customSwitch_' + rowData.id; // Assuming you have an 'id' field in your data var switchElement = $(td).find('#webapi_' + switchId); console.log("WEBAPI Element: ", switchElement); var isChecked = rowData.webapi ? 'checked' : ''; // Set the isChecked variable based on rowData.webapi switchElement.change(function () { datatable_WEBAPI_alarm.draw(); }); }, }, ], }); // Initialize the tabs in the WEBAPI modal $('#webapiTabs a').click(function (e) { e.preventDefault(); $(this).tab('show'); }); setTimeout(function() { datatable_WEBAPI_alarm.ajax.reload(null, false); }, 30000); }
已查阅DataTables官方文档,仍无法定位问题,恳请协助解决。
内容的提问来源于stack exchange,提问作者080_coder_from_jap
相关产品推荐
相关产品推荐

