点击其他页面会重定向到第一页。我该如何纠正这个问题?

问题描述 投票:0回答:1

经过研究,我发现下面的微调代码可以解决我的问题(我的其他html已通过此修复)

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手册,研究了它,但我确实需要一些帮助,谢谢。

javascript jquery ajax datatable datatables
1个回答
0
投票
setTimeout(function() {
                   datatable_FTP.ajax.reload(null, false);
                 }, 30000);

将其修复,确保将其排除在表循环之外

成功视频是第三个

© www.soinside.com 2019 - 2024. All rights reserved.