Pagex 中自定义导出
第一步: 先自己写pagex 列表查询接口,在查询的时候缓存上一次查询的过滤条件。
@RequestMapping("/underLineData")
@RequiresPermissions("toll_collector_report:see")
public Pager findPager(HttpServletRequest request, HttpServletResponse response)
{
Map<String,Object> paramMap = super.getPageTurnNum(request);
paramMap.put("groupCode", super.getSessionuser(request).getGroupCode());
paramMap.put("parkIds", DataPermissonContext.getDataPermissonMap().get("parkIds"));
request.getSession().setAttribute(this.getClass().getName() + "preLoadParam",paramMap);
List<TollCollectorReportVo> rows = tollCollectorReportService.findListData(paramMap);
paramMap.put("end",null);
int total = tollCollectorReportService.findListData(paramMap).size();
Pager<TollCollectorReportVo> pager = new Pager<>(total, rows);
return pager;
}
第二步:自己写导出的控制器
@RequestMapping({"exportReportExcel"})
@RequiresPermissions("toll_collector_report:see")
public void exportReportExcel(HttpServletRequest request, HttpServletResponse response) {
Map<String,Object> paramMap = (Map<String, Object>) request.getSession().getAttribute(this.getClass().getName() + "preLoadParam");
List dataList = tollCollectorReportService.findListData(paramMap);
ExcelExportTools.exportExcel(dataList, request, response);
}
第三步:禁用掉pagex自带的导出
在js中配置 disableButtons [‘export’];
第四部:自己写自定义按钮和方法做导出。
var _fieldArray = getExcelFields();//如果要过滤某个列不导出或者增加列,修改_fieldArray 即可,debugger即可看到他数据格式
$.ajax({
url: "${path.basePath}/ms/tollCollector/setExportField",
type: "post",
contentType: "application/json;charset=utf-8",
dataType: "json",
data: json2str(_fieldArray),
success: function (result) {
window.location.href = "${path.basePath}/ms/tollCollector/exportReportExcel?excelName=" + encodeURIComponent('收费员线下收费报表');
}
});
系统会使用列表中的字段配置当做excel导出配置进行导出。
当前内容版权归 fhs-opensource 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 fhs-opensource .