반응형
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | var IAMakeTable = { currentTabId : "", jsonHead : [], initialize : function(array){ IAMakeTable.IAtable(array, currentTabId, function(){ IAMakeTable.IASetResToTable(array,0,0,0); }); $('.nav-tabs a[data-toggle="tab"]').on('click',function(e){ IAMakeTable.whenClickTab(e); }); }, create : function(id, content){ var str = '<div class="row">'+ '<div class="col-xs-12">'+ '<div id="'+id+'" data-set="'+content["data-set"]+'">'+ '<table class="table table-bordered" data-set="'+content["data-set"]+'" id="'+id+'_table" title="'+content.title+'"></table>' + '<div id="pager_'+content.title+'"></div>'+ '</div>'+ '</div>'+ '</div>'; return str; }, IAtable : function(array, currentTabId, callback){ IAGridTableIdInfo.tableInfoArray = []; IAMakeTable.jsonHead = []; IAMakeTable.currentTabId = currentTabId; function makeGridObject(id,caption,rownumbers,multiselect,width,height,columns,data){ this.id = id; this.caption = (caption!="false")? "■ "+caption: " "; this.rownumbers = rownumbers? rownumbers:null; this.multiselect = multiselect? multiselect:null; this.width = width; this.height = height; this.columns = columns; this.data = data; } function setAttrForGrid(d, tableTabId){ if(d.title != undefined){var tbId = d.title;} if(d.head != undefined){var tbHead = d.head; if(d["data-set"] != undefined) { IAMakeTable.jsonHead.push({"url" : d["data-set"], "head" : d.head}); }else{ /*수정 진행 2018-09-20*/ alert("json 파일에 요청할 url주소를 작성하셔야 합니다."); } } if(d.body != undefined){var tbBody = d.body;} if(d.bodyUrl != undefined){ var tbBodyUrl = d.bodyUrl;} if(d.width != undefined){var width = d.width;} if(d.height != undefined){var height = d.height;} if(d.multiselect != undefined){var multiselect = d.multiselect;} if(d.rownumbers != undefined){var rownumbers = d.rownumbers;} if(d.caption != undefined){var caption = d.caption;} if(d.head[0] != undefined){ if(d.head[0].cellattr != undefined) var test = d.head[0].cellattr; } var GridObject = new makeGridObject(tbId, caption, rownumbers, multiselect, width, height, tbHead, tbBody); GridObject["tabId"] = tableTabId; IAArticle.table.push(GridObject); } array.forEach(function(d,i){setAttrForGrid(d.obj,d.tabId); });//end forEach if(callback) callback(); }, IASetResToTable : function(array, head, body, submitUrl){ IAArticle.table.forEach(function(GridObject,i){ array.forEach(function(d,i){ if(GridObject.id == d.obj.title){ var tableDivId = d.id; tableDivId = tableDivId.substr(0, tableDivId.lastIndexOf("_table")); GridObject["tableDivId"] = tableDivId; if($('#'+d.id).attr('data-set') == submitUrl){ var innerContent = '<table class="table table-bordered" data-set="'+submitUrl+'" id="'+d.id+'" title="'+d.obj.title+'"></table>'+ '<div id="pager_'+d.obj.title+'"></div>'; $('#' + tableDivId).empty(); $('#' + tableDivId).html(innerContent); GridObject.columns = head; GridObject.data = body; } if($('#'+d.id).attr('data-set') == submitUrl || 0 == submitUrl){ /*최초 상태(0) 이거나, 조회 버튼 클릭 한 영역에만 생깁니다. */ IAMakeTable.makeIAGrid(array, GridObject, function(){ IAMakeTable.makeIconDiv(tableDivId); IAMakeTable.setTableArea(IAMakeTable.currentTabId); }); } } }); }); }, makeIAGrid : function(array, GridObject, callback){ new IAGrid(GridObject, array); if( callback ){ callback(); } }, makeIconDiv : function(tableDivId){ var parentsDiv = "#"+ tableDivId; if( !$(" "+parentsDiv+" .ui-jqgrid-titlebar div").hasClass('iconDiv')){ var str = "<div class='iconDiv'>" + "<span class='jqPdf'><i class='fa fa-download'></i></span>" + "<span class='jqExcel'><i class='fa fa-file-excel-o'></i></span>" + "<span class='jqPrint'><i class='fa fa-print'></i></span>" + "<div>"; $(" "+parentsDiv+" .ui-jqgrid-titlebar").append(str); } var area = $(" "+parentsDiv+" ").find(".ui-jqgrid-titlebar").find(".iconDiv"); area.find(".jqExcel").on("click", function(){ /* 임시용 */ var jqObj = $(""+parentsDiv+"_table"); jqGridToExcel(jqObj, "엑셀이름"); }); area.find(".jqPrint").on("click", function(){ var jqObj = $(""+parentsDiv+""); jqGridPrint(jqObj); }); }, setTableArea : function(currentTabId){ var captionId; var pagerId; var divId; var tableId; IAGridTableIdInfo.tableInfoArray.forEach(function(d,i){ captionId = d.captionId; pagerId = d.pagerId; divId = d.divId; tableId = d.tableId; $("#"+captionId).width("100%"); $("#"+pagerId).width("100%"); var wrapDivId = "scrollArea"; var scollAreaId = tableId+'_'+wrapDivId; if($("#"+divId).find("#"+scollAreaId).length == 0){ $("#"+divId + ' .ui-jqgrid-hdiv').before('<div id="'+scollAreaId+'" style="overflow-x : scroll;"></div>'); $("#"+divId + ' .ui-jqgrid-hdiv').appendTo('#'+scollAreaId); $("#"+divId + ' .ui-jqgrid-bdiv').appendTo('#'+scollAreaId); $("#"+divId + ' .ui-jqgrid-sdiv').appendTo('#'+scollAreaId); /* 수정 진행, 없는 테이블도 존재 */ var parentHeight = $('#'+scollAreaId).parents('#'+divId).closest('.form-group').css('min-height'); $('#'+scollAreaId).css('min-height', parentHeight); } }); }, whenClickTab : function(e){ currentTabId = $(event.target).attr('href'); IAMakeTable.currentTabId = currentTabId; IAMakeTable.setTableArea(currentTabId); $("#tab-select option:selected").removeAttr("selected"); $('#tab-select option[value='+currentTabId+']').attr("selected","selected"); } } | cs |
반응형
'Programming Language > Javascript' 카테고리의 다른 글
[Javascript] 탭 이동 코드 / html, Javascript, css (0) | 2018.10.18 |
---|---|
[Javascript] ia-grid.js 코드 샘플 (0) | 2018.10.11 |
[Javascript] 두 날짜 일수 차이 계산 (0) | 2018.08.01 |
[Javascript] 익스플로러11 post방식 팝업 문제 (0) | 2018.08.01 |
[Javascript] 개월 수 및 일수 윤년 포함 날짜 계산 (스크랩) (0) | 2018.07.30 |