如何防止数据表翻页?

时间:2019-07-12 09:40:19

标签: jquery events datatables

我在HTML代码中使用了jQuery Datatable。我需要防止单击“上一个”按钮或“下一个”按钮后Datatable翻页,因为某些条件无法满足,例如某些修改未保存。

无论我尝试什么,它始终会保持分页!我的问题有解决方案吗?非常感谢!

var html = ""
for (var i = 0; i < data.list.length; i++) {
  html = html + '<tr>';
  var j = i + 1;
  html = html + '<td style="display: none;" >' + data.list[i].id + '</td>';
  // html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + j + '</td>';
  html = html + "<td align='center' valign='center'><input type='checkbox' style='width:15px;height:15px'></td>";
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].itemCode + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].itemName + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].itemClass + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].itemTypeName + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].unitCode + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].upperLimit + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].floorLimit + '</td>';
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + data.list[i].assistUnit + '</td>';

  var note = data.list[i].memo === null ? "" : data.list[i].memo;
  html = html + '<td style="text-align: center;vertical-align: middle" class="addUserId">' + note + '</td>';
  html = html +
    `<td class="nprint" style="text-align: center; vertical-align: middle; width: 200px">
      <div class="btn-group"> 
        <button type="button" onclick="modify(this)" class="btn btn-success" data-toggle="modal" data-target="#myModal3">
          修改
        </button>
        <button type="button" onclick="dell(this)" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
          删除
        </button>
      </div>
    </td>`
  html = html + '</tr>';
}

$("#table").html(html);

$('#item_info').DataTable({
  "columnDefs": [{
    "orderable": false,
    "targets": [1]
  }],
  "order": [
    [2, "asc"]
  ],
  language: {
    "sProcessing": "处理中...",
    "sLengthMenu": "显示 _MENU_ 项结果",
    "sZeroRecords": "没有匹配结果",
    "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
    "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
    "sInfoPostFix": "",
    "sSearch": "搜索:",
    "sUrl": "",
    "sEmptyTable": "表中数据为空",
    "sLoadingRecords": "载入中...",
    "sInfoThousands": ",",
    "oPaginate": {
      "sFirst": "首页",
      "sPrevious": "上页",
      "sNext": "下页",
      "sLast": "末页"
    },
    "oAria": {
      "sSortAscending": ": 以升序排列此列",
      "sSortDescending": ": 以降序排列此列"
    }
  }
});

0 个答案:

没有答案