티스토리 뷰
자바 웹 개발을 하다 보면 그리드를 뭘쓸것인가 고민이 많다.
유료를 쓰자니 돈이들고.. 무료를 쓰자니 성능을 알 수 없고..
그중 무료이면서 괜찮은 DataTable을 소개하고자 한다.
DataTable 을 사용해 자바 스프링 환경에서 파라미터 전달,페이징,테이블 세팅 방법을 살펴본다.
@RequestMapping("/web/getList")
public @ResponseBody Map getList(HttpServletRequest request, Web form) throws Exception{
Map resultMap = new HashMap<String, Object>();
int limit = form.getLength();
int start = form.getStart();
int page = (start/limit)+1;
form.setLimit(limit);
form.setPage(page);
List<WebList> resultList = webMapper.getList(form);
int totCount = (resultList.size() == 0) ? 0 : resultList.get(0).getTotCount();
int temp = (int)(Math.floor(totCount / limit));
resultMap.put("data", resultList);
return resultMap;
}
<div id="popupModal">
<table class="" id="tempList">
<colgroup>
<col width="">
<col width="">
</colgroup>
<thead>
<tr>
<th class="">컬럼헤더0</th>
<th class="">컬럼헤더1</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="footer">
<a href="#" id="btnClose" data-dismiss="modal"><spring:message code='system.close'/></a>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
initTable();
});
function initTable(){
$("#tempList").DataTable({
searching:false,
pageLength:500,
bLengthChange:false,
pagingType:"simple_numbers",
bInfo:false,
aoColumnDefs:[{bSortable:false, aTargets:[0,1]}],
sScrollY:(480),
language: {
paginate: {
"previous": '<i class="icon wb-chevron-left-mini"></i>',
"next": '<i class="icon wb-chevron-right-mini"></i>'
}
},
serverSide:true,
ajax: {
type : 'POST'
url : '<c:url value="/web/getList"/>',
data : function(d){
d.groupId = "${session.groupId}",
d.groupId2 = "${session.groupId2}"
},
dataType : "JSON"
},
columns:[
{data:"email", className:"text-center break-all"},
{data:"mailName", className:"text-center break-all"}
]
});
}
</script>
<select id="getList" resultType="com.WebList">
/* com.WebList */
SELECT A.*
FROM (
SELECT EMAIL
, MAIL_NAME
, COUNT(*) OVER AS TOTCOUNT
, FLOOR((ROW_NUMBER() OVER(ORDER BY UPDATE_DT DESC) -1 ) / #{LIMIT} + 1) AS PAGE
FROM TABLE
WHERE PARA=#{groupId} AND groupId2=#{groupId2}
ORDER BY EMAIL
) A
WHERE A.PAGE = #{page}
</select>
package com;
public class WebList extends Link implements Serializable{
private String email;
private String mailName;
public String getEmail(){
return email;
}
public void setEmail(String email){
this.email = email;
}
public String getMailName(){
return mailName;
}
public void setMailName(String mailName){
this.mailName = mailName;
}
}
package com;
public class Link{
private int totCount;
private int page;
public int getTotCount(){
return totCount;
}
public void setTotCount(int totCount){
this.totCount = totCount;
}
public int getPage(){
return page;
}
public void setPage(int page){
this.page = page;
}
}
위와 같이 DataTable을 이용해 간단하게 값(파라미터를) 넘기고 myBatis를 통해 데이터를 가져와 (페이징 포함)
DataTable에 세팅까지 하는것을 살펴 보았다.
더 자세한 내용은 DataTable 홈페이지를 살펴보면 될것이다.
- Total
- Today
- Yesterday
- webix
- 오라클
- Python
- 자바 smtp
- C
- 플러터
- ocajp
- 스크래핑
- C언어
- php
- ocjap
- EC
- 포인터
- 이클립스
- 인포믹스
- KG
- proc
- JDBC
- 문자열
- esql
- MySQL
- XE3
- 파이썬
- xe addon
- 파싱
- XE
- 프로씨
- xe애드온
- 자바
- 라이믹스 모듈
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |