public String returnHtml(HttpServletRequest request, HttpServletResponse response,Map map) throws Exception { TableFacade tableFacade = new TableFacadeImpl("ListId", request); tableFacade.setColumnProperties("Column1","Column2","Column3","Column4","Column5","Column6"); tableFacade.setStateAttr("restore"); tableFacade.setExportTypes(response, EXCEL); setMessageDataAndLimitVariables(tableFacade,map); // Limit limit = tableFacade.getLimit(); // 导出数据 if (tableFacade.getLimit().isExported()) { this.exportDataReceive(tableFacade); return null; } // final int rowStart = limit.getRowSelect().getRowStart(); HtmlTable table = (HtmlTable) tableFacade.getTable(); table.getTableRenderer().setWidth("98%"); Row row = table.getRow(); HtmlColumn column1 = (HtmlColumn) row.getColumn("Column1"); column1.setFilterable(false); column1.setSortable(false); column1.getHeaderRenderer().setHeaderEditor(new SelfDefinedCheckboxHeaderEditor("checkedAll(this)")); column1.getCellRenderer().setCellEditor(new CellEditor() { public Object getValue(Object item, String property, int rowcount) { Object value = new BasicCellEditor().getValue(item, "ID", rowcount); HtmlBuilder html = new HtmlBuilder(); html.input().type("checkbox").name("messageId").value(value.toString()).end(); return html.toString(); } }); HtmlColumn column2= (HtmlColumn) row.getColumn("Column2"); column2.setTitle("字段名2"); HtmlColumn column3= (HtmlColumn) row.getColumn("Column3"); column3.setTitle("字段名3"); HtmlColumn column4= (HtmlColumn) row.getColumn("Column4"); column4.setTitle("字段名4"); column4.setFilterable(false); HtmlColumn column5= (HtmlColumn) row.getColumn("Column5"); column5.setTitle("字段名5"); column5.getCellRenderer().setCellEditor(new CellEditor() { public Object getValue(Object item, String property, int rowcount) { Object value = new BasicCellEditor().getValue(item, property, rowcount); try { return value.toString(); } catch (Exception e) { e.printStackTrace(); return ""; } } }); HtmlColumn column6= (HtmlColumn) row.getColumn("Column6"); column6.setTitle("短信内容"); HtmlToolbar toolbar = new HtmlToolbar(); toolbar.enablePageNumbers(true); tableFacade.setToolbar(toolbar); return tableFacade.render(); } protected void setMessageDataAndLimitVariables(TableFacade tableFacade,Map map) throws Exception { Limit limit = tableFacade.getLimit(); if (!limit.isComplete()) { int totalRows = this.getTotalMessageCount(map); tableFacade.setTotalRows(totalRows); } int rowStart = limit.getRowSelect().getRowStart(); int rowEnd = limit.getRowSelect().getRowEnd(); List<Map> items = this.selectTotalMessage(map, rowStart, rowEnd); tableFacade.setItems(items); } public void exportDataReceive(TableFacade tableFacade){ tableFacade.setColumnProperties("Column2","Column3","Column4","Column5","Column6"); Table table = tableFacade.getTable(); //不读中文名字??转码! table.setCaption("data"); Row row = table.getRow(); Column createTime= row.getColumn("Column2"); createTime.setTitle("字段2"); Column groupName= row.getColumn("Column3"); groupName.setTitle("字段3"); Column guestName = row.getColumn("Column4"); guestName.setTitle("字段4"); Column cellphone = row.getColumn("Column5"); cellphone.setTitle("字段5"); Column msg = row.getColumn("Column6"); msg.setTitle("字段6"); tableFacade.render(); }
HtmlColumn opr = row.getColumn("ID"); opr.setFilterable(false); opr.setSortable(false); opr.setTitle("操作"); if(isSearch){ opr.getCellRenderer().setCellEditor(new CellEditor() { public Object getValue(Object item, String property, int rowcount) { Object value = new BasicCellEditor().getValue(item, property, rowcount); HtmlBuilder html = new HtmlBuilder(); html.a().href().quote().append("javascript:selectGuest(").append( value.toString()).append(")").quote().title("查看").close(); html.img().src("../images/new/edit.gif").close(); html.aEnd(); html.nbsp(); return html.toString(); } }); HtmlToolbar toolbar = new HtmlToolbar(); toolbar.enablePageNumbers(true); tableFacade.setToolbar(toolbar); }else{ opr.getCellRenderer().setCellEditor(new CellEditor() { public Object getValue(Object item, String property, int rowcount) { Object value = new BasicCellEditor().getValue(item, property, rowcount); HtmlBuilder html = new HtmlBuilder(); html.a().href().quote().append("javascript:modifyGuest(").append( value.toString()).append(")").quote().title("修改").close(); html.img().src("../images/new/edit.gif").close(); html.aEnd(); html.nbsp(); html.a().href().quote().append("javascript:deleteGuest(") .append(value).append(")").quote().title("删除") .close(); html.img().src("../images/del.gif").close(); html.aEnd(); return html.toString(); } }); tableFacade.setToolbar(new ExtraGuestCustomToolbar()); }