Authored by qinchao

sql查询增加分页功能

@@ -126,7 +126,7 @@ @@ -126,7 +126,7 @@
126 126
127 <div class="form-group"> 127 <div class="form-group">
128 <div class="col-sm-offset-2 col-sm-10"> 128 <div class="col-sm-offset-2 col-sm-10">
129 - <button class="btn btn-primary" onclick="query()" style="margin-top: 50px;">提交查询</button> 129 + <button class="btn btn-primary" onclick="queryFromBtn()" style="margin-top: 50px;">提交查询</button>
130 </div> 130 </div>
131 </div> 131 </div>
132 </div> 132 </div>
@@ -135,18 +135,19 @@ @@ -135,18 +135,19 @@
135 <!-- result form--> 135 <!-- result form-->
136 <div class="widget-box"> 136 <div class="widget-box">
137 <div class="widget-title"> 137 <div class="widget-title">
138 - <h5>查询结果[单次查询最多显示30条数据]</h5> 138 + <h5>查询结果</h5>
139 </div> 139 </div>
140 <div class="widget-content nopadding"> 140 <div class="widget-content nopadding">
141 <div id="resultDiv"> 141 <div id="resultDiv">
142 142
143 </div> 143 </div>
144 - <div id="jobsTable"> 144 + <div id="simplePageInfoDiv">
145 145
146 </div> 146 </div>
147 - <div id="simplePageInfoDiv"> 147 + <div id="jobsTable">
148 148
149 </div> 149 </div>
  150 +
150 </div> 151 </div>
151 </div> 152 </div>
152 153
@@ -229,6 +230,7 @@ @@ -229,6 +230,7 @@
229 */ 230 */
230 function ctlSubmit(event) { 231 function ctlSubmit(event) {
231 if (event.ctrlKey && event.keyCode == 13) { 232 if (event.ctrlKey && event.keyCode == 13) {
  233 + page_info_current_page_index=0;
232 query(); 234 query();
233 } 235 }
234 } 236 }
@@ -293,24 +295,16 @@ @@ -293,24 +295,16 @@
293 return sql; 295 return sql;
294 } 296 }
295 297
296 - function first(){ 298 + function queryFromBtn(){
297 page_info_current_page_index=0; 299 page_info_current_page_index=0;
298 query(); 300 query();
299 } 301 }
300 302
301 - function prev(){  
302 - page_info_current_page_index--;  
303 - query();  
304 - }  
305 - function next(){  
306 - page_info_current_page_index++;  
307 - query();  
308 - }  
309 303
310 /** 304 /**
311 * 发送请求,并构造返回结果 305 * 发送请求,并构造返回结果
312 */ 306 */
313 - function query(){ 307 + function query(fromPaginationFlag){
314 var queryThings=$.trim($("#queryContent").val()); 308 var queryThings=$.trim($("#queryContent").val());
315 queryThings=removeAnnotateTypeOne(queryThings); 309 queryThings=removeAnnotateTypeOne(queryThings);
316 queryThings=removeAnnotateTypeTwo(queryThings); 310 queryThings=removeAnnotateTypeTwo(queryThings);
@@ -357,7 +351,7 @@ @@ -357,7 +351,7 @@
357 if(resp.data.queryDescr){ 351 if(resp.data.queryDescr){
358 $("#resultDiv").append("<br>"+"<span style='color:red'>"+resp.data.queryDescr+"</span>"); 352 $("#resultDiv").append("<br>"+"<span style='color:red'>"+resp.data.queryDescr+"</span>");
359 } 353 }
360 - $("#simplePageInfoDiv").hide(); 354 +
361 $("#jobsTable").show(); 355 $("#jobsTable").show();
362 if(resp.data.queryCount>0){ 356 if(resp.data.queryCount>0){
363 $("#jobsTable").table({ 357 $("#jobsTable").table({
@@ -367,7 +361,9 @@ @@ -367,7 +361,9 @@
367 columns:resp.data.jsonArrayColumn , 361 columns:resp.data.jsonArrayColumn ,
368 data:resp.data.jsonArrayData 362 data:resp.data.jsonArrayData
369 }); 363 });
370 - showPageDiv(resp.data.hasNext); 364 + if(!fromPaginationFlag){
  365 + showPageDiv(resp.data);
  366 + }
371 }else{ 367 }else{
372 $("#jobsTable").hide(); 368 $("#jobsTable").hide();
373 } 369 }
@@ -384,32 +380,25 @@ @@ -384,32 +380,25 @@
384 }); 380 });
385 } 381 }
386 382
387 - function showPageDiv(hasNext){  
388 - var firstPage='<li><a href="#" onclick="first()"><span aria-hidden="false">首页</span></a></li>';  
389 - var prevPage="";  
390 - var prevPage_click=' href="#" onclick="prev()" ';  
391 - if(page_info_current_page_index==0){  
392 - prevPage="disabled";  
393 - prevPage_click="";  
394 - firstPage=''; 383 + function showPageDiv(respDataMap){
  384 + if(respDataMap.showPi){
  385 + $("#simplePageInfoDiv").html("");
  386 + $("#simplePageInfoDiv").pagination({
  387 + totalCount:respDataMap.totalPi,
  388 + pageSize:respDataMap.pageSizePi,
  389 + //currentPage : respDataMap.currentPagePi,
  390 + onSelectPage: function(currentPage, pageSize) {
  391 + //alert("currentPage= " + currentPage + ",pageSize= " + pageSize);
  392 + page_info_current_page_index = (currentPage -1 );
  393 + $("#jobsTable").table("loadLoaclData",[]);
  394 + query(true);
395 } 395 }
396 - var nextPage="";  
397 - var nextPage_click=' href="#" onclick="next()" ';  
398 - if("no"==hasNext){  
399 - nextPage="disabled";  
400 - nextPage_click="";  
401 - }  
402 - var htmlDiv='';  
403 - htmlDiv += '<div role="pagination">';  
404 - htmlDiv += '<div class="col-md-4 column"></div>';  
405 - htmlDiv += '<div class="col-md-8 column">';  
406 - htmlDiv += '<ul class="pagination pull-right" style="margin: 5px;">';  
407 - htmlDiv += firstPage;  
408 - htmlDiv += '<li class="'+prevPage+'"><a'+prevPage_click+'><span aria-hidden="false">上一页</span></a></li>';  
409 - htmlDiv += '<li class="active"><a aria-label="'+page_info_current_page_index+'" pagenum="'+page_info_current_page_index+'"><span aria-hidden="false">'+(page_info_current_page_index*1+1)+'</span></a></li>';  
410 - htmlDiv += '<li class="'+nextPage+'"><a'+nextPage_click+'><span aria-hidden="false">下一页</span></a></li></ul>';  
411 - htmlDiv += '</div></div>';  
412 - $("#simplePageInfoDiv").html(htmlDiv); 396 + });
  397 +
413 $("#simplePageInfoDiv").show(); 398 $("#simplePageInfoDiv").show();
  399 + }else{
  400 + $("#simplePageInfoDiv").hide();
  401 + $("#simplePageInfoDiv").html("");
  402 + }
414 } 403 }
415 </script> 404 </script>