jqgrid
$("#tblist1")
.jqGrid('navGrid', '#pager', {
add: false,
edit: false,
del: false,
search: false,
refresh: false
})
.jqGrid( 'navButtonAdd', "#pager", {
caption : "Export to CSV",
buttonicon : "ui-icon-arrowthickstop-1-s",
onClickButton : function() {
$("#tblist1").jqGrid('excelExport',{"url":"./excel/as.do"});
},
position : "first",
title : "Export to CSV",
});
controller
@RequestMapping("/excel/as")
public ResponseEntity<String> csvAsList(Locale locale, AsVO asVo,
@RequestParam Map<String, String> map) throws Exception {
Comm.jqgridSearchFormSetVO(map.get("filters"), asVo);
List<AsVO> excelList = asService.excelList(asVo); // DB에서 가져온 데이터리스트
String data = new DataToCSV().as(excelList);
HttpHeaders header = new HttpHeaders();
header.add("Content-Disposition", "attachment; filename=\"" + "as.csv" + "\"");
header.add("Content-Type", "text/csv; charset=MS949");
return new ResponseEntity<String>(data, header, HttpStatus.OK);
}
servlet-context.xml - UTF-8 프로젝트라서 예외처리용
<beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:bean class="org.springframework.http.converter.StringHttpMessageConverter">
<beans:property name="supportedMediaTypes">
<beans:value>text/plain;charset=UTF-8</beans:value>
</beans:property>
</beans:bean>
</beans:list>
</beans:property>
</beans:bean>