From 979d7361bd1e976b813020f96126d1291ec1bdb7 Mon Sep 17 00:00:00 2001 From: KNKIM Date: Tue, 27 Jul 2021 09:34:06 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A4=91=EA=B0=84=EB=B0=B1=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nlib/bbs/web/BoardController.java | 26 +++--- .../WEB-INF/jsp/nlib/board/listQnAs.jsp | 85 ++++++------------- src/main/webapp/js/jsgrid/nlib-jsgrid.js | 15 ++-- 3 files changed, 52 insertions(+), 74 deletions(-) diff --git a/src/main/java/nlib/bbs/web/BoardController.java b/src/main/java/nlib/bbs/web/BoardController.java index 472608d9..ab46338b 100644 --- a/src/main/java/nlib/bbs/web/BoardController.java +++ b/src/main/java/nlib/bbs/web/BoardController.java @@ -94,9 +94,13 @@ public class BoardController extends NlibCommonController public String listQnAs(HttpServletRequest req, Authentication authentication, @RequestParam Map paramMap, ModelMap model) { String searchKeyword = paramMap.get("searchKeyword"); - String pageIndex = paramMap.get("pageIndex"); - String pageSize = paramMap.get("pageSize"); - + String pageIndex = paramMap.get("pageIndex"); + String pageSize = paramMap.get("pageSize"); + + log.debug("listQnAs > pageIndex = " + pageIndex); + log.debug("listQnAs > pageSize = " + pageSize); + log.debug("listQnAs > searchKeyword = " + searchKeyword); + // 페이징 사이즈 코드 목록 조회 DataApiReqVO reqVOforPageSize = new DataApiReqVO(); reqVOforPageSize.setAuthKey(createAuthKey(req, authentication)); @@ -105,12 +109,13 @@ public class BoardController extends NlibCommonController DataApiResVO resVOforPageSize = codeService.listCodes(reqVOforPageSize); // 반환 정보 - model.addAttribute("pageIndex" , pageIndex); + model.addAttribute("pageIndex" , pageIndex); model.addAttribute("pageSize" , pageSize); model.addAttribute("searchKeyword", searchKeyword); + model.addAttribute("pageSizeCodes", resVOforPageSize.getList()); - - log.debug("listQnAs > pageSizeCodes : " + resVOforPageSize.getList()); + //log.debug("listQnAs > pageSizeCodes : " + resVOforPageSize.getList()); + return "nlib/board/listQnAs"; } @@ -128,9 +133,9 @@ public class BoardController extends NlibCommonController String pageIndex = paramMap.get("pageIndex"); String pageSize = paramMap.get("pageSize"); - log.debug("listQnAs > pageIndex = " + pageIndex); - log.debug("listQnAs > pageSize = " + pageSize); - log.debug("listQnAs > searchKeyword = " + searchKeyword); + log.debug("listQnAsAjax > pageIndex = " + pageIndex); + log.debug("listQnAsAjax > pageSize = " + pageSize); + log.debug("listQnAsAjax > searchKeyword = " + searchKeyword); //------------------------------- // REQ VO 구성 @@ -148,8 +153,6 @@ public class BoardController extends NlibCommonController // 요청 DataApiResVO resVO = boardService.listQnAs(reqVO); - - //------------------------------- // JSON변환 응답 처리 //------------------------------- @@ -157,7 +160,6 @@ public class BoardController extends NlibCommonController // {data: [{...}], // itemsCount: 255 // } - HashMap retMap = new HashMap(); retMap.put("data", resVO.getList()); retMap.put("itemsCount", resVO.getRecordTotCount()); diff --git a/src/main/webapp/WEB-INF/jsp/nlib/board/listQnAs.jsp b/src/main/webapp/WEB-INF/jsp/nlib/board/listQnAs.jsp index 5f166124..ee5976aa 100644 --- a/src/main/webapp/WEB-INF/jsp/nlib/board/listQnAs.jsp +++ b/src/main/webapp/WEB-INF/jsp/nlib/board/listQnAs.jsp @@ -95,10 +95,12 @@ var articleTypes = [ //======================================================= $("#jsGrid").jsGrid({ - autoload: true, /* 화면로드된 후, 자동 loadData 처리 여부 */ - + /*autoload: true, 화면로드된 후, 자동 loadData 처리 여부 */ + autoload: false, + pageSize : $("#pageSize").val(), controller: { loadData: function (filter) { + var data = $.Deferred(); //====================================== @@ -106,17 +108,18 @@ $("#jsGrid").jsGrid({ //====================================== var reqUrl = "${pageContext.request.contextPath}/board/listQnAsAjax.do"; var searchKeyword = document.articleForm.searchKeyword.value; - //var pageIndex = document.articleForm.pageIndex.value; - var pageIndex = filter.pageIndex; - //var pageSize = document.articleForm.pageSize.value; - var pageSize = filter.pageSize; + var pageIndex = ( filter && filter.pageIndex ? filter.pageIndex : $("#pageIndex").val()); + var pageSize = ( filter && filter.pageSize ? filter.pageSize : $("#pageSize").val()); var inputData = { "searchKeyword" : searchKeyword /*encodeURIComponent(searchKeyword)*/ - , "pageIndex" : pageIndex + , "pageIndex" : pageIndex , "pageSize": pageSize}; console.log(JSON.stringify(inputData)); + console.log(JSON.stringify(filter)); + + $("#pageIndex").val(pageIndex); //-------------------------------------- // 요청 처리 @@ -151,7 +154,7 @@ $("#jsGrid").jsGrid({ fn_view_detail(articleNo); }, - + //====================================== // 그리드 컬럼 정의 (각 요청에 맞게 조정) //====================================== @@ -165,17 +168,14 @@ $("#jsGrid").jsGrid({ }); $("#pageSize").on("change", function(e) { - //alert(e.target.value); - //$("#jsGrid").jsGrid("option", "pageIndex", 1).("option", "pageSize", e.target.value); - //$("#jsGrid").jsGrid("loadData", {"pageIndex":2,"pageSize":50}); - //fn_search_article(); - //$("#jsGrid").controller.loadData({"pageIndex":2,"pageSize":50}); - //$("#jsGrid").jsGrid("loadData()"); - $("#jsGrid").jsGrid("search", {'pageIndex':'2','pageSize':e.target.value}); - //$("#jsGrid").jsGrid("search", {'pageIndex':2,'pageSize':50}); + //$("#jsGrid").jsGrid("search", {'pageIndex':1,'pageSize':e.target.value}); + $("#pageIndex").val("1"); + fn_search_article(); }); -$("#jsGrid").jsGrid("option", "pageIndex", $("#pageIndex").val(), "pageSize", $("#pageSize").val()); +$("#btnSearch").on("click", function(e) { + fn_search_article(); +}); // 선택한 게시글 상세 보기로 이동 function fn_view_detail(articleNo) { @@ -184,49 +184,20 @@ function fn_view_detail(articleNo) { $("#articleForm").submit(); } -function fn_search_article() { - $("#jsGrid").jsGrid("loadData"); +function fn_search_article(pageSize, pageIndex) { + console.log("fn_search_article 1 : param > " + pageSize + ", " + pageIndex); + console.log("fn_search_article 2 : recalc > " + (pageSize ? pageSize : $("#pageSize").val()) + ", " + (pageIndex ? pageIndex : $("#pageIndex").val())); + $("#jsGrid").jsGrid("search" + , {'pageSize':(pageSize ? pageSize : $("#pageSize").val()), + 'pageIndex':(pageIndex ? pageIndex : $("#pageIndex").val()) + } + ); } - function fn_search_article2() { - var searchKeyword = document.articleForm.searchKeyword.value; - var pageIndex = document.articleForm.pageIndex.value; - var pageSize = document.articleForm.pageSize.value; +function fn_init() { + $("#jsGrid").jsGrid("search", {'pageIndex':$("#pageIndex").val(),'pageSize':$("#pageSize").val()}); +} - var inputData = { - "searchKeyword" : searchKeyword /*encodeURIComponent(searchKeyword)*/ - , - "pageIndex" : pageIndex, - "pageSize" : pageSize - }; - - //alert(JSON.stringify(inputData)); - - $.ajax({ - url : "${pageContext.request.contextPath}/board/listQnAsAjax.do", - contentType : "application/json; charset=utf-8", /* */ - type : "post", - data : JSON.stringify(inputData), - dataType : 'json', /* Server Response Data Type */ - async : true, - success : function(returnData, status) { - var jsonObj = JSON.parse(returnData); - alert("record=" + JSON.stringify(jsonObj)); - $("#jsGrid").jsGrid("data") = jsonObj; - }, - error : function(data) { - alert("조회에 실패하였습니다.\n" + data.code + " : " + data.message); - } - }); - } - - function fn_init() { - //fn_search_article(); - document.articleForm.searchKeyword.focus(); - //$("#jsGrid").jsGrid("loadData"); - //$("#jsGrid").jsGrid("data") = client2; - } - diff --git a/src/main/webapp/js/jsgrid/nlib-jsgrid.js b/src/main/webapp/js/jsgrid/nlib-jsgrid.js index 1acd03e9..c5336f2c 100644 --- a/src/main/webapp/js/jsgrid/nlib-jsgrid.js +++ b/src/main/webapp/js/jsgrid/nlib-jsgrid.js @@ -1085,11 +1085,15 @@ }, loadData : function(filter) { + + // NLIB : 파라메터값이 기존 설정값으로 대체 막음 + if(filter) { + if(filter.pageSize) this.pageSize = filter.pageSize; + if(filter.pageIndex) this.pageIndex = filter.pageIndex; + } + filter = filter || (this.filtering ? this.getFilter() : {}); - - //$.extend(filter, this._loadStrategy.loadParams(), this - // ._sortingParams()); - + $.extend(this._loadStrategy.loadParams(), filter, this ._sortingParams()); @@ -1685,7 +1689,8 @@ }, openPage : function(index) { - this._grid.loadData(); + //this._grid.loadData(); + this._grid.loadData({"pageIndex": index}); // NLIB }, loadParams : function() {