Want to calculate records per page for pagination

362 Views Asked by At

Hi I am new to javascript. The issue is that when the user enters the page range that needs to be printed, it calculated the wrong end page number, and it prints the only 3 pages from that range. Here are my functions for printing and pagination.

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

There are 0 best solutions below