想要计算每页分页的记录数

时间:2013-12-10 17:14:28

标签: javascript printing pagination range records

您好我是javascript的新手。问题是当用户输入需要打印的页面范围时,它会计算错误的结束页码,并打印该范围内仅有的3页。这是我的打印和分页功能。

function printPage()
{
var rn = parseInt($('reportNumber').value) ;
var s = parseInt($('startpage').value) ;
var e = parseInt($('endpage').value) ;
var l = parseInt($('linesPerPage').value) ;
var i = (((e-s)+1)*l) ; //records per page
$('printpg').hide() ;
$('MsgWait').show();
buildPaginationLinks(,i,i,rn);
setTimeout("window.print();",5000) ;
}

function createReport(rptNum,stPage,recPPg)
{

/*
 *  We will be sending 3 parameters to the query generation:
 *      - Reporting Name:           rptNameId
 *      - Report Type:              rptType
 *      - Starting Page:            stPage
 */
$('msg').innerHTML = "Gathering Records.  One Moment Please." ;
if (recPPg == null || recPPg == '!undefined')
{var recPerPg = parseInt($('recordsperpage').value) ;}
else
{var recPerPg = recPPg; }

var callback = function(response){
    if(response.error){ // display error
        $('msg').innerHTML = response.error ;
        setTimeout("$('msg').innerHTML = ''",10000);//reset the result   
after 10sec
}
document.getElementById('container').style.width = "85%";
response.data != null ? displayOJRptData(response) : '';
};


$j.ajax({
mode: 'queue',
    type: 'GET',
    dataType: 'json',
    url: baseURL + php01, 
    data: 'task=buildRptQuery&rptNameId=' + rptNameID
            + '&rptJobName=' + rptCJobName 
            + '&rptType=' +  rptType
            + '&stpage=' + stPage 
            + '&recperpg=' + recPerPg
            + '&rptSelection=' + rptSelection
            + '&rptIgnoreShipped=' + rptIgnoreShip
            + '&product='+product
            + '&startdate='+startdate
            + '&enddate='+enddate
            + '&excludeOld='+excludeOld
            + '&dummy=' + new Date().getTime(),
    success: callback
}); 



 }

function displayOJRptData(ojData)
{
$('reportcriteria').hide() ;
$('frm_nameinput').hide() ;
$('frm_jobinput').hide() ;
$('reporttype').hide() ;

$('reportview').show() ;
//var MsgWait = MsgWaitFunction();
// build report title
var rptTitle = buildReportTitle(parseInt(ojData.rptType)) ;
// build the header
var rptHeader = buildReportHeader() ;
// build table
var rptBody = buildReportBody(ojData.data) ;
// build footer
var rptFooter =   
    buildReportFooter(parseInt(ojData.rptType),ojData.ttlRows,ojData.sqlcount) ;
// build the pagination links
  var rptPagination =   
  buildPaginationLinks(ojData.ttlRows,ojData.recPerPg,parseInt(ojData.currPg),
  parseInt(ojData.rptType)) ;

$('thereport').innerHTML = rptTitle + rptHeader + rptBody + rptFooter +   
  rptPagination ;

  }


function buildPaginationLinks(rows,perpg,pagenum,rptnum) 
{
pages = '<tr align="center"><td align="center" colspan="11">' ;

numrows = rows ;
perpage = perpg ;
pageno = pagenum ;
rptnum = rptnum ;

lastpage = Math.ceil(numrows/perpage) ;

if (pageno < 1)
{
pageno = 1 ;
}
else 

if (pageno > lastpage)
{
pageno = lastpage ;
}

if (pageno == 1)
{
pages += 'FIRST | PREVIOUS ' ;
}
else
{
pages += ' <a href="#" onClick="createReport(' + rptnum + ',1,' + perpage +    
')">FIRST</a> ' + '&nbsp' ;
prevpage = pageno - 1 ;

pages += ' <a href="#" onClick="createReport(' + rptnum + ',' +   prevpage + ',' + 
perpage + ')">PREVIOUS</a>  ' + '&nbsp';
}

pages += '(' ;
pages += ' <a href="#" onClick="setPrintPg(' + "'createReport'" + ',' + rptnum + ',' + 
pageno + ',' + perpage + ')">PRINT</a>  ' + '&nbsp' ;
pages += ' | Page ' + pageno + ' of ' + lastpage + ' ) ' ;

if (pageno == lastpage)
{
pages += ' NEXT | LAST ' ;
}
else
{
nextpage = pageno + 1 ;
pages += ' <a href="#" onClick="createReport(' + rptnum + ',' + nextpage + ',' + 
perpage + ')">NEXT</a>  ' + '&nbsp' ;
pages += ' <a href="#" onClick="createReport(' + rptnum + ',' + lastpage + ',' + 
perpage + ')">LAST</a>  '+ '&nbsp' ;
}   pages = '<tr align="center"><td align="center" colspan="11">' ;

numrows = rows ;
perpage = perpg ;
pageno = pagenum ;
rptnum = rptnum ;

lastpage = Math.ceil(numrows/perpage) ;

if (pageno < 1)
{
pageno = 1 ;
}
else 
if (pageno > lastpage)
{
pageno = lastpage ;
}

if (pageno == 1)
{
pages += 'FIRST | PREVIOUS ' ;
}
else
{
pages += ' <a href="#" onClick="createReport(' + rptnum + ',1,' + perpage + 
')">FIRST</a> ' + '&nbsp' ;
prevpage = pageno - 1 ;
pages += ' <a href="#" onClick="createReport(' + rptnum + ',' + prevpage + ',' + 
perpage + ')">PREVIOUS</a>  ' + '&nbsp';
}

pages += '(' ;
pages += ' <a href="#" onClick="setPrintPg(' + "'createReport'" + ',' + rptnum + ',' + 
pageno + ',' + perpage + ')">PRINT</a>  ' + '&nbsp' ;

pages += ' | Page ' + pageno + ' of ' + lastpage + ' ) ' ;

if (pageno == lastpage)
{
pages += ' NEXT | LAST ' ;
}
else
{
nextpage = pageno + 1 ;
pages += ' <a href="#" onClick="createReport(' + rptnum + ',' + nextpage + ',' +    
perpage + ')">NEXT</a>  ' + '&nbsp' ;
pages += ' <a href="#" onClick="createReport(' + rptnum + ',' + lastpage + ',' +   
perpage + ')">LAST</a>  '+ '&nbsp' ;
}

pages += '</td></tr></table>';
return pages ;


pages += '</td></tr></table>';
return pages ;
}

0 个答案:

没有答案