Pagex 中自定义导出

第一步: 先自己写pagex 列表查询接口,在查询的时候缓存上一次查询的过滤条件。

  1. @RequestMapping("/underLineData")
  2. @RequiresPermissions("toll_collector_report:see")
  3. public Pager findPager(HttpServletRequest request, HttpServletResponse response)
  4. {
  5. Map<String,Object> paramMap = super.getPageTurnNum(request);
  6. paramMap.put("groupCode", super.getSessionuser(request).getGroupCode());
  7. paramMap.put("parkIds", DataPermissonContext.getDataPermissonMap().get("parkIds"));
  8. request.getSession().setAttribute(this.getClass().getName() + "preLoadParam",paramMap);
  9. List<TollCollectorReportVo> rows = tollCollectorReportService.findListData(paramMap);
  10. paramMap.put("end",null);
  11. int total = tollCollectorReportService.findListData(paramMap).size();
  12. Pager<TollCollectorReportVo> pager = new Pager<>(total, rows);
  13. return pager;
  14. }

第二步:自己写导出的控制器

  1. @RequestMapping({"exportReportExcel"})
  2. @RequiresPermissions("toll_collector_report:see")
  3. public void exportReportExcel(HttpServletRequest request, HttpServletResponse response) {
  4. Map<String,Object> paramMap = (Map<String, Object>) request.getSession().getAttribute(this.getClass().getName() + "preLoadParam");
  5. List dataList = tollCollectorReportService.findListData(paramMap);
  6. ExcelExportTools.exportExcel(dataList, request, response);
  7. }

第三步:禁用掉pagex自带的导出

在js中配置 disableButtons [‘export’];

第四部:自己写自定义按钮和方法做导出。

var _fieldArray = getExcelFields();//如果要过滤某个列不导出或者增加列,修改_fieldArray 即可,debugger即可看到他数据格式

  1. $.ajax({
  2. url: "${path.basePath}/ms/tollCollector/setExportField",
  3. type: "post",
  4. contentType: "application/json;charset=utf-8",
  5. dataType: "json",
  6. data: json2str(_fieldArray),
  7. success: function (result) {
  8. window.location.href = "${path.basePath}/ms/tollCollector/exportReportExcel?excelName=" + encodeURIComponent('收费员线下收费报表');
  9. }
  10. });

系统会使用列表中的字段配置当做excel导出配置进行导出。