반응형
페이지 로드 시 테이블 만들고, ajax로 데이터 조회 한 후 동적으로 행 만들어 추가하기!
나는 테이블의 컬럼명도 동적으로 만들기 위해 thead부분을 추가하였다.
controller에서 ArrayList를 넘겨주었고, jsp페이지에서 userList라는 변수에 담아 반복문을 돌려 행을 추가하였다.
$.ajax({
url:"selectUserList.do",
type:"POST",
data : { dept_id : dept_id },
success:function(data){
var userList = data;
var tr = '<thead>'+
'<tr>' +
'<th>이름</th>'+
'<th>사번 </th>'+
'<th>이메일 </th>'+
'<th>SC권한 </th>'+
'<th>직위 </th>'+
'</tr>'+
'</thead>';
$.each(userList , function(i){
tr += '<td>' + userList[i].user_nm_ko + '</td><td>' + userList[i].user_id + '</td><td>' + userList[i].email + '</td><td>' + userList[i].enable + '</td><td>' + userList[i].pos_nm + '</td></tr>';
});
$("#userList").append(tr); // 테이블에 추가
});
}
});
반응형
'웹개발정보' 카테고리의 다른 글
[JQuery] checkBox 체크여부 확인(전체체크), 체크된 값만 가져오기 (0) | 2021.04.12 |
---|---|
[JQuery] 테이블 정렬 (Table sort) (1) | 2021.04.12 |
[Spring] Login_Save ID, PWD (cookie) (1) | 2021.01.18 |
[Spring] dataTables 사용법 정리 (feat. ajax) (0) | 2021.01.18 |
[css] a태그 페이지 이동 막기 (0) | 2020.12.16 |
댓글