BootStrap Table 和EasyUi table后台分页时前台删除最后一页所有数据refresh刷新后无数据问题处理方法

954 阅读1分钟

问题

在实现表格列表时,删除最后一页造成最后一页无数据问题;

原因

主要是页码超出范围请求数据为空

BootStrap Table 解决方案:

通过修改bootstrap-table.js的initServer方法中的查询success回调函数解决,将该回调函数改为:

function (res) { 
    res = calculateObjectValue(that.options, that.options.responseHandler, [res], res); 
        /**处理页码错误问题开始 为避免有不分页的数据判断total*/
         if(res.total!=undefined&&res.total!=0&&res.data.length==0){//总记录数大于0,但当前页记录数为0,则此时页码超过了最大页码误
            that.options.pageNo = Math.ceil(res.total/that.options.pageSize);//最后一页(总页数)
            that.initServer();
          return;
        }
    /**处理页码错误问题结束*/
    that.load(res); 
    that.trigger('load-success', res); 
   }

即当总记录数不为0而当前页的记录数为0时将页码设为最后一页重新请求数据:

 if(res.total!=undefined&&res.total!=0&&res.data.length==0){//总记录数大于0,但当前页记录数为0,则此时页码超过了最大页码误
    that.options.pageNo = Math.ceil(res.total/that.options.pageSize);//最后一页(总页数)
    that.initServer();
  return;
}

EasyUi table 解决方案:

在onLoadSuccess中判断这里我的入参是pageNo和pageSize 
if(datas.total!=undefined&&datas.total!=0&&datas.rows.length==0){//总记录数大于0,但当前页记录数为0,则此时页码超过了最大页码误
         that.pageNo = Math.ceil(datas.total/that.pageSize);//最后一页(总页数)
          $(this).datagrid("reload");
         return;
         }