You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 15:02:07