본문 바로가기

Backend/Utils

[Feat] Pagenation, Select 옵션

반응형

Pagenation

function goToPage(page){
    loading.start();
    $("#nowPage").val(page);
    $("#frm0").attr("action", "/amng/dataVariableMng/dataVariableMng.do").submit();
}
<!-- jQuery -->
<form id="frm0" name="frm0" method="post">
                <input type="hidden" id="nowPage" name="nowPage" value="${custDataVariableVO.nowPage}">
                </form>
                ...
                <div class="board-paging" id="paging"></div>
                ...
                <script>
    $(document).ready(function () {
        mcenAdminPageNavigator('${custDataVariableVO.totalCnt}', '${custDataVariableVO.pageRow}', $('#nowPage').val(), 'paging', '${custDataVariableVO.totalPage}', '${custDataVariableVO.viewPage}', '');
    });
</script>
@RequestMapping(value = "/amng/dataVariableMng/dataVariableMngList.do")
    public String displayVariableMngList(@ModelAttribute("dataVariableVO") AdminSearchVO paramPageVO,
                                         HttpServletRequest request, Model model, HttpSession session) throws IOException, SQLException {
        AdminSearchVO pageVO = paramPageVO;
        System.out.println(pageVO);
        Map<String, ?> flashMap = RequestContextUtils.getInputFlashMap(request);
        if (flashMap != null) {
            pageVO = (AdminSearchVO) flashMap.get("dataVariableVO");
            session.setAttribute("dataVariableVO", pageVO);
        } else {
            if (session.getAttribute("dataVariableVO") != null) {
                pageVO = (AdminSearchVO) session.getAttribute("dataVariableVO");
            }
        }

        // 카테고리 조회
        pageVO.setStatusType("Y");
        List<DataVariableVO> category = adminDataVariableService.selectDataVariableGroupList(pageVO);
        model.addAttribute("category", category);
        /*
         * List<SubCodeVO> category = adminCodeService.selectSubCodeList(63);
         * model.addAttribute("category", category);
         */
		
		/*if(pageVO.getCtgryType() == 0) {
			pageVO.setCtgryType(category.get(0).getGroupSeq());
		}*/

        int listTotalCnt = adminDataVariableService.selectDataVariableTotalCnt(pageVO);

        pageVO.configurePageVO(pageVO.getNowPage(), Constants.VIEW_ROW, Constants.VIEW_PAGE, listTotalCnt);

        List portalUrlList = adminDataVariableService.selectDataVariableTotalList(pageVO);

        model.addAttribute("list", portalUrlList);
        model.addAttribute("dataVariableVO", pageVO);

        return "/amng/dataVariableMng/dataVariableMngList";
    }

 

 

DB-select옵션 연결

<!-- Jquery -->
...
<tr>
	<th>여기</th>
	<td colspan="3">
		<select id="here" style="width: 300px;" onchange="fn_selectOption()">
		</select>
	</td>
</tr>
...
// JavaScript
//$(document).ready(function () {
// 	// fn_searchCustDataset(); // 이렇게 하면 계속 select option이 늘어남
//    document.addEventListener("DOMContentLoaded", function () {
//    	fn_searchCustDataset();
//	});
//});                       
//                        
//function fn_selectOption(){
//	const jsonData = {"uesYn": "Y"}
//	fnMcenAjaxJson("POST", "url", JSON.stringify(jsonData), resultAjaxSelectOption, "");
//}

//Flag이용
let hasDataLoaded = false; // document.ready밖에


function fn_selectOption(){
if (!hasDataLoaded) {
        const jsonData = { "uesYn": "Y" };
        fnMcenAjaxJson("POST", "/amng/dataVariableMng/ajaxSearchCustDatasetVersion", JSON.stringify(jsonData), resultAjaxSearchCustDatasetCallback, "");
        hasDataLoaded = true;
    }
}

function resultAjaxSelectOption(data){ // ajax시 data에 JSON값이 담기므로 parameter를 data로 잡는다.
	loading.end();
	console.log(data.resultMap.ArrayName);
	if(getResultMsg(data.resultCode) == 'OK'){
		for(var i=0; i<data.resultMap.ArrayName.length; i++){
			const info = data.resultMap.ArrayName[i];
			$("#here").append('<option value="' + info.Seq + '">'
            					+ info.Name + '_v.' + info.Version + '</option>');
		}

		if(data.resultMap.ArrayName.length > 1) {
			$("#here").val(data.resultMap.ArrayName[1].datasetListSeq)
		}
	} else {
		alert(getResultMsg(data.resultCode));
	}
}

 

// controller
@PostMapping(value = "url")
    public ResponseEntity<?> ajaxSelectOption(@RequestBody SampleVO paramVO, HttpServletRequest request,
                             Authentication authentication, Model model) throws IOException, SQLException {

        CommonResult commonResult;
        commonResult = responseService.getSuccessResult(getCsrfToken(request));
        HashMap<String, Object> resultMap = new HashMap<>();

        UserVO user = getCurrentUser(authentication);
        paramVO.setInsertId(user.getUserId());
        paramVO.setUpdateId(user.getUserId());

        resultMap.put("ArrayName", sampleService.selectOptionList(paramVO));

        commonResult.setResultMap(resultMap);

        return ResponseEntity.ok(commonResult);
    }
반응형