473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pagination problem

149 100+
hi,
i need to implement pagination in my project..i m using struts2..in my jsp page im implementing pagination using javascript...it is showing error as 'rows is undefined'...i tried the same with sample its working fine..if i implement in my application it is showing error..
Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2.     .pg-normal {
  3.         color: #0000FF;
  4.         font-weight: normal;
  5.         text-decoration: none;
  6.         cursor: pointer;
  7.     }
  8.     .pg-selected {
  9.         color: #800080;
  10.         font-weight: bold;
  11.         text-decoration: underline;
  12.         cursor: pointer;
  13.     }
  14. </style>
  15. <script type="text/javascript">
  16.     function Pager(tableName, itemsPerPage) {
  17.         this.tableName = tableName;
  18.         this.itemsPerPage = itemsPerPage;
  19.         this.currentPage = 1;
  20.         this.pages = 0;
  21.         this.inited = false;
  22.         this.showRecords = function(from, to) {
  23.             var rows = document.getElementById(tableName).rows;
  24.             // i starts from 1 to skip table header row
  25.             for (var i = 1; i < rows.length; i++) {
  26.                 if (i < from || i > to)
  27.                     rows[i].style.display = 'none';
  28.                 else
  29.                     rows[i].style.display = '';
  30.             }
  31.        }
  32.         this.showPage = function(pageNumber) {
  33.             if (! this.inited) {
  34.                 alert("not inited");
  35.                 return;
  36.             }
  37.             var oldPageAnchor = document.getElementById('pg'+this.currentPage);
  38.             oldPageAnchor.className = 'pg-normal';
  39.             this.currentPage = pageNumber;
  40.             var newPageAnchor = document.getElementById('pg'+this.currentPage);
  41.             newPageAnchor.className = 'pg-selected';
  42.             var from = (pageNumber - 1) * itemsPerPage + 1;
  43.             var to = from + itemsPerPage - 1;
  44.             this.showRecords(from, to);
  45.         }
  46.         this.prev = function() {
  47.             if (this.currentPage > 1)
  48.                 this.showPage(this.currentPage - 1);
  49.         }
  50.         this.next = function() {
  51.             if (this.currentPage < this.pages) {
  52.                 this.showPage(this.currentPage + 1);
  53.             }
  54.         }
  55.         this.init = function() {
  56.             var rows = document.getElementById(tableName).rows;
  57.             var records = (rows.length - 1);
  58.             this.pages = Math.ceil(records / itemsPerPage);
  59.             this.inited = true;
  60.         }
  61.         this.showPageNav = function(pagerName, positionId) {
  62.             if (! this.inited) {
  63.                 alert("not inited");
  64.                 return;
  65.             }
  66.             var element = document.getElementById(positionId);
  67.             var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> &#171 Prev </span> | ';
  68.             for (var page = 1; page <= this.pages; page++)
  69.                 pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
  70.             pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next »</span>';
  71.             element.innerHTML = pagerHtml;
  72.         }
  73.     }
  74. </script><table  id="manage"  border="1" width="100%" class="headertable" cellpadding="0" cellspacing="0">
  75.         <thead>
  76.             <tr>
  77.                 <th align="left">
  78.                     ContentID
  79.                 </th>
  80.                 <th align="left">
  81.                     Title
  82.                 </th>
  83.                 <th align="left">
  84.                     Description
  85.                 </th>
  86.                 <th align="left">
  87.                     Charge
  88.                 </th>
  89.                 <th align="left">
  90.                     Rating
  91.                 </th>..and the code goes on at the end of form
  92. </table>
  93.     <div id="pageNavPosition"></div>
  94.  
  95. </s:form>
  96. <script type="text/javascript"><!--
  97.     var pager = new Pager('manage', 3);
  98.     pager.init();
  99.     pager.showPageNav('pager', 'pageNavPosition');
  100.     pager.showPage(1);
  101.     //--></script>   
  102.  
Oct 28 '10 #1
1 1756
madhuriks
149 100+
any help regarding my post
Oct 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tarakaram | last post by:
hello friends I am facing with this pagination problem for few days. i desperately looking for solution any advice or help will be highly appreciated. my code will be generating the records...
2
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
0
by: George Ter-Saakov | last post by:
Trying to quickly create paginated grid. So i am using ListView. Unfortunatelly pagination works a little strange. Pagination control appears correctly. But when i click "2" page postback...
2
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all Got a weird problem with pagination on a datagrid in asp.net 1.1. It's populated depending on user selected criteria (it either displays all or 1 record). It works fine in the...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
25
pradeepjain
by: pradeepjain | last post by:
<html> <head> <script src="jquery.js" type="text/javascript"></script> <script src="jquery.rating.js" type="text/javascript" language="javascript"></script> <link...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
2
by: lisles | last post by:
can somebody please help me with this.im extracting values from the database and displaying them.but since the results are huge i've done pagination.the first page gets displayed fine.but when i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.