db의 member테이블을 불러옴
원하는 정보를 선택하고 아래 선택이라는 글자를 클릭하면
아이디정보를 ajax로 data에 저장한다.
data:{"id": $('#grid').jqGrid("getGridParam","selrow")}
이렇게 저장한뒤 ajax 연결 페이지에서 저장한 아이디로 db에서 검색하여 상세정보를 JSONObject에 담아서 받아온다.
그리고 아래에 뿌려줌!!
jqgrid1.jsp
=============================
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
#tdTag,#a {
border: 2px double #FF5E00;
width: 100px;
font-family: "휴먼매직체";
text-align: center;
}
</style>
<link rel="stylesheet" type="text/css" href="scripts/css/jquery-ui-
1.10.3.custom.css" />
<link rel="stylesheet" href="scripts/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="scripts/css/ui.multiselect.css" />
<script src="http://code.jquery.com/jquery-1.7.js">
</script>
<script src="scripts/js/i18n/grid.locale-en.js">
</script>
<script src="scripts/js/jquery.jqGrid.min.js">
</script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#grid').jqGrid({
url:'bb.jsp',
datatype:'json',
jsonReader:{page:'page',root:'list',total:'total'},
colNames:['id','pw','ADDR','TEL'],
colModel:[
{name:'id',width:50, editable:false},
{name:'pw',width:50, editable:true},
{name:'addr',width:50, editable:true},
{name:'tel',width:50, editable:true}
],
width:500,
viewrecords:true,
rowNum:3,
rowList:[3,6,9],
caption:'회원리스트',
pager:'#pager',
editurl:"cc.jsp"
});
$("#grid").navGrid("#pager",
{add:true,del:true,edit:true,search:true,refresh:true});
$("#aTag").click(function(){
con.innerHTML = "";
$.ajax({
url:"dd.jsp",
dataType:"json",
data:{"id": $('#grid').jqGrid("getGridParam","selrow")},
success:function(data){
$("<table/>", {
id : "TbTag3"
}).appendTo("#con");
title = [ "id","pw","addr","tel" ];
var item=[];
var items = [];
$.each(title, function(index) {
item.push("<td id=a>" + title[index] + "</td>");
});
$("<tr/>", {
html : item[0] + item[1] + item[2]+ item[3]
}).css({
background: "#FFFFB4",
}).appendTo("#TbTag3");
var cnt = 0;
$.each(title, function(index3) {
var k=title[cnt++];
items.push("<td id=tdTag>" +data.member[k]+ "</td>");
});
$("<tr/>", {
html : items[0] + items[1] + items[2]+ items[3]
}).appendTo("#TbTag3");
}
})
});
});
</script>
</head>
<body>
<table id="grid"></table>
<div id="pager"></div>
<a href="#" id="aTag">선택</a>
<div id="con"></div>
</body>
</html>
bb.jsp
=====================================
<%@page import="kr.co.seoulit.member.to.MemberBean"%>
<%@page import="kr.co.seoulit.common.to.ListForm"%>
<%@page import="kr.co.seoulit.member.dao.MemberDAOImpl"%>
<%@page import="java.lang.reflect.Member"%>
<%@page import="kr.co.seoulit.member.dao.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*" %>
<%@ page import="net.sf.json.*"%>
<%
int pagenum=Integer.parseInt(request.getParameter("page"));
int rowsize=Integer.parseInt(request.getParameter("rows"));
MemberDAOImpl dao=(MemberDAOImpl)MemberDAOImpl.getInstance();
int dbcount=dao.selectRowCount();
ListForm listForm=new ListForm();
listForm.setRowsize(rowsize);
listForm.setPagenum(pagenum);
listForm.setDbcount(dbcount);
int sr=listForm.getStartrow();
int er=listForm.getEndrow();
List<MemberBean> list=dao.selectMemberList(sr,er);
HashMap<String,Object> map=new HashMap<String,Object>();
int pagecount=listForm.getPagecount();
map.put("page",pagenum);
map.put("total",pagecount);
map.put("list",list);
JSONObject jsonObject=JSONObject.fromObject(map);
/* Enumeration<String> arr=request.getParameterNames();
while(arr.hasMoreElements()){
String n=arr.nextElement();
String v=request.getParameter(n);
System.out.println("이름:"+n);
System.out.println("값:"+v);
} */
out.println(jsonObject);
%>
cc.jsp
==========================================
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*" %>
<%
Enumeration<String> e=request.getParameterNames();
while(e.hasMoreElements()){
String name=e.nextElement();
String value=request.getParameter(name);
System.out.println(name+","+value);
}
%>
dd.jsp
===========================================
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*" %>
<%@ page import="kr.co.seoulit.member.dao.*" %>
<%@ page import="kr.co.seoulit.member.to.*" %>
<%@ page import="net.sf.json.*"%>
<%
MemberDAO dao=MemberDAOImpl.getInstance();
MemberBean member=dao.selectMember(request.getParameter("id"));
HashMap<String,Object> map=new HashMap<String,Object>();
map.put("member",member);
JSONObject jsonObject= new JSONObject();
jsonObject.putAll(map);
out.println(jsonObject);
%>
'개발하자 > jgGrid' 카테고리의 다른 글
jqgrid 선택한 정보 보기 (0) | 2015.03.19 |
---|---|
jqgrid 참고사이트 (0) | 2015.03.18 |
선택누르면 jqgrid에서 id값 alert에 띄우기 (0) | 2015.03.17 |
editurl사용하기 (0) | 2015.03.17 |
페이지카운트 (0) | 2015.03.17 |