Authored by qinchao

sql查询增加分页功能

... ... @@ -126,7 +126,7 @@
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-primary" onclick="query()" style="margin-top: 50px;">提交查询</button>
<button class="btn btn-primary" onclick="queryFromBtn()" style="margin-top: 50px;">提交查询</button>
</div>
</div>
</div>
... ... @@ -135,18 +135,19 @@
<!-- result form-->
<div class="widget-box">
<div class="widget-title">
<h5>查询结果[单次查询最多显示30条数据]</h5>
<h5>查询结果</h5>
</div>
<div class="widget-content nopadding">
<div id="resultDiv">
</div>
<div id="jobsTable">
<div id="simplePageInfoDiv">
</div>
<div id="simplePageInfoDiv">
<div id="jobsTable">
</div>
</div>
</div>
... ... @@ -229,6 +230,7 @@
*/
function ctlSubmit(event) {
if (event.ctrlKey && event.keyCode == 13) {
page_info_current_page_index=0;
query();
}
}
... ... @@ -293,24 +295,16 @@
return sql;
}
function first(){
function queryFromBtn(){
page_info_current_page_index=0;
query();
}
function prev(){
page_info_current_page_index--;
query();
}
function next(){
page_info_current_page_index++;
query();
}
/**
* 发送请求,并构造返回结果
*/
function query(){
function query(fromPaginationFlag){
var queryThings=$.trim($("#queryContent").val());
queryThings=removeAnnotateTypeOne(queryThings);
queryThings=removeAnnotateTypeTwo(queryThings);
... ... @@ -357,7 +351,7 @@
if(resp.data.queryDescr){
$("#resultDiv").append("<br>"+"<span style='color:red'>"+resp.data.queryDescr+"</span>");
}
$("#simplePageInfoDiv").hide();
$("#jobsTable").show();
if(resp.data.queryCount>0){
$("#jobsTable").table({
... ... @@ -367,7 +361,9 @@
columns:resp.data.jsonArrayColumn ,
data:resp.data.jsonArrayData
});
showPageDiv(resp.data.hasNext);
if(!fromPaginationFlag){
showPageDiv(resp.data);
}
}else{
$("#jobsTable").hide();
}
... ... @@ -384,32 +380,25 @@
});
}
function showPageDiv(hasNext){
var firstPage='<li><a href="#" onclick="first()"><span aria-hidden="false">首页</span></a></li>';
var prevPage="";
var prevPage_click=' href="#" onclick="prev()" ';
if(page_info_current_page_index==0){
prevPage="disabled";
prevPage_click="";
firstPage='';
function showPageDiv(respDataMap){
if(respDataMap.showPi){
$("#simplePageInfoDiv").html("");
$("#simplePageInfoDiv").pagination({
totalCount:respDataMap.totalPi,
pageSize:respDataMap.pageSizePi,
//currentPage : respDataMap.currentPagePi,
onSelectPage: function(currentPage, pageSize) {
//alert("currentPage= " + currentPage + ",pageSize= " + pageSize);
page_info_current_page_index = (currentPage -1 );
$("#jobsTable").table("loadLoaclData",[]);
query(true);
}
var nextPage="";
var nextPage_click=' href="#" onclick="next()" ';
if("no"==hasNext){
nextPage="disabled";
nextPage_click="";
}
var htmlDiv='';
htmlDiv += '<div role="pagination">';
htmlDiv += '<div class="col-md-4 column"></div>';
htmlDiv += '<div class="col-md-8 column">';
htmlDiv += '<ul class="pagination pull-right" style="margin: 5px;">';
htmlDiv += firstPage;
htmlDiv += '<li class="'+prevPage+'"><a'+prevPage_click+'><span aria-hidden="false">上一页</span></a></li>';
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>';
htmlDiv += '<li class="'+nextPage+'"><a'+nextPage_click+'><span aria-hidden="false">下一页</span></a></li></ul>';
htmlDiv += '</div></div>';
$("#simplePageInfoDiv").html(htmlDiv);
});
$("#simplePageInfoDiv").show();
}else{
$("#simplePageInfoDiv").hide();
$("#simplePageInfoDiv").html("");
}
}
</script>
... ...