I have a table displaying results from a database, and I am adding some paging/navigation buttons to it, such as 'prev', 'next', etc. These are being constructed for now as submit input buttons that are wrapped with a form tag and some hidden inputs to pass the needed querystring values back to the page itself, which means each form and element in the form should have an ID attribute.
Now, I'd love to add the navigation to both the top and bottom of the table, so I've modularized the navigation generation into a single routine I call whenever needed. This of course leads to duplicate form and element IDs in the page when there is more than one navigation bar included.
I've thought of passing some 'count' parameter to the routine so that when generating the HTML it could append that value to the IDs, and there are other solutions, such as using a global counter (ugly), etc, but I thought I'd poll the crowd and see what others have done in this situation.
Thanks,
Paul
Of the solutions you have thought of thus far, I would suggest the tactic that you mention first in the last paragraph. Passing a query string variable and loading X number of records including the number passed (doing error checking of course to make sure that some sneaky user doesn't try to put random characters in the query string) would resolve your issue.
Another option (since you are obviously doing codebehind for loading from the DB) is to create a session variable and assign the value to that when the links are clicked and use it to generate the list.
For both instances, when the page loads you can take the current value being passed and add X (number of rows in results shown +1) and change the value passed by the links.
I recently made a paginator myself, but approached it in a totally different way. I used php to generate the numbers, and each number (page) had a tag with an href that was mywebsite.php?page=x. That way you can use a get method, grab the page number from the url, and loop through as many times as you want for the number of pages displayed.
As they say, there is more than one way to skin a cat. I prefer the url passing method because I can stay away from forms and ID's in their entirety, making it so that the paginator can go wherever I decide to slap it in (and however many times).
Here's a snapshot of how I went about generating it. Hope it gives you some ideas!
/*PAGE NUMBERS*/
// ceil rounds a decimal up to the next integer
$pages=ceil(($totalrows-1)/$tablesize); //we subtract 1 from total rows because it counts 0
//(int) typecasts the $pages variable, so that it is divisible by an integer (ceil makes it a float)
$pages=(int)$pages;
//displays all the pages with their links
//if page count is less than 7 (the full paginator), display all pages
if($pages<=7){
for($i=1;$i<=$pages;$i++){
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
//if page count is more than 7
}else{
//if page # is less than 4, display pages up to 7, so that there are always 7 pages available (makes the buttons not jump around)
if($page<=4){
for($i=1;$i<=7;$i++){
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
//if page # is less than 4 away from the end, display pages $pages-7
}elseif($page>=$pages-3){
for($i=$pages-6;$i<=$pages;$i++){
//8,9,10,11,12,13,14,15
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
//if it's in between the ends, do this
}else{
for($i=1;$i<$pages+1;$i++){
//limit the number of visible pages to 7
if(($i>=$page-3)&&($i<=$page+3)){
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
}
}
}
There might have been some confusion it seems over what I was looking for, but in a nutshell, a simple way to avoid the duplicate ID issue when using a form-based paging solution that can be displayed multiple times on the same page (above and below tabular data, for example). My solution is to model it after the PHPMyAdmin paging, in that I simply remove the IDs for the form elements for now and reference the data being passed via the name attribute, which allows for duplicates.
Related
I need to create a report and export it to .docx that shows the page number and total number of pages in the first page header (e.g. "1 of 5") and only show the page number in the header for all other pages (e.g. "2", "3").
What I've tried so far
Creating 2 text boxes in the header and setting their visibility to "=Globals!PageNumber=1" and "=not Globals!PageNumber=1" or "=Globals!OverallPageNumber=1" and "=not Globals!OverallPageNumber=1".
Both text boxes either exist on all pages or don't exist at all.
Setting the header to not print on the first page, adding only the page number to the header and adding a text box with the expression code.PageNumber & " of " & code.TotalPages to the top of the report body and adding
Function PageNumber() As String
Return Me.Report.Globals!PageNumber.ToString()
End Function
Function TotalPages() As String
Return Me.Report.Globals!TotalPages.ToString()
End Function
to report code, because you can't use global variables in report body. But the text box in the body always shows "1 of 1" no matter how many pages there are.
Is there something I did wrong in my attempts that I don;t understand?
Is there another way of achieving the result I need?
I'm not sure which version of ssrs I'm using but solutions that work with any version would help me a lot.
Add your header then add a textbox to the header and set the expression to this.
="Page " &
Globals!PageNumber &
IIF(Globals!PageNumber = 1,
" of " & Globals!TotalPages,
"")
This will show "Page 1 of 5" on the first page and then just "Page 2" etc on subsequent pages.
I'm like to admit that my knowledge of HTML is very little.
Assume we have a button on our pagepage that calls a javascript function: check().
The check() function withdraws an array (contantly updated) of values, e.g. string, from a server. If each element of the array has a certain property, e.g. contain a letter "a", then it wants to print those strings on the webpage.
The upperbound of the array size retrieved from the server is known but we do not know in advance how many elements satisfies the condition checked by check().
Question how to print the elements found by check() on a HTML file (a webpage).
Let's assume javascrip is in the the HTLM file too.
With something like <div id="destination"></div> in the HTML as a placeholder, you can use JavaScript to loop through your array of items and insert each one into the HTML with:
document.getElementById('destination').innerHTML += '<p>' + myData + '</p>';
I have a form in MS Access that allows users to enter data they collect from the field and that form also has the option to compile all of the information into a formal report. The report contains a cover sheet and a table of contents as well as leaves section header pages for additional documents to be attached when printed out/exported.
There are 2 things that execute before their processes are actually finished:
One subroutine creates many formatted tables but the tables only get created with the appropriate data, the formatting does not apply right away and as a result, the formatting finally kicks in once the document is done typing and will delete any extra pages. This is affecting the second problem.
Since the page numbering for each page is not the same, sections are used so that each page can have a unique footer with the page number included in that. A loop is used to run through the document and unlink all headers and footers from the previous ones. It then starts from the beginning of the document and moves from footer to footer and writes the page number. That code is below:
While Not Selection.Information(wdActiveEndPageNumber)
If Selection.Information(wdActiveEndPageNumber) = (Section_Page + 1) Then
Selection.TypeText "Page: " & (pgNum + Section_Length)
pgNum = pgNum + Section_Length
Else
Selection.TypeText "Page: " & pgNum
End If
pgNum = pgNum + 1
ActiveWindow.ActivePane.View.NextHeaderFooter 'move to the next page's footer
Wend
The problem that I am having with this section of code is that the Selection does not always move to the next footer fast enough and as a result footers that belong on the next page sometimes cram onto the same page as another footer and the footer looks something like "Page: 5Page: 6" rather than "Page: 5" on one and "Page: 6" on the next.
Please do not suggest the built in Word page numbering - I shortened the code here, there are anywhere between 3 and 7 sections that need spacing. I think if there was a way to get the code to execute asynchronously that block of code will work.
A stop-gap measure would be to insert one (or several) line(s) of
DoEvents
after the change and before ActiveWindow....NextHeaderFooter. That command yields execution to the OS. That may give Word the time it needs to catch up.
Of course, you would do better to avoid using ActiveWindow... altogether and iterate through the sections with a For loop.
My scenario is, I'm returning a list of value as json from controller to view, then want to show just the first record on my form & after pressing the down arrow key, want to show the second & so on.
Is it possible to traverse the total json list one by one at client side or I have to return single record every time from the server with key press event via ajax?
The way I see it you have bunch of options, one possibility might be to return your results, generate html elements in your view and hide all but the first one (with CSS). Something like (just to give you an idea):
#model List<string>
#for (int i = 0; i < Model.Count; i++)
{
<div class="#((i == 0) ? "name-highlighted" : "name")">#Model[i]</div>
}
And in your css something like:
.name {
display: none;
}
.name-highlighted {
/* You get the idea */
}
Having said that, if don't want to load all the items, you can fetch the first one only (while keeping a count) and fetch every subsequent with an ajax call.
This is the part of the code for paging(when you see page 1,page 2...at the bottom).The $_SERVER[QUERY_STRING] is used to copy what was searched on previous page so that page number 2 displays results for same query.
The problem is that on page 2 the "query string" is added with page number &page=2 so when you click for page 3 the $_SERVER[QUERY_STRING] copies the query(which i need to be copied,eg. ?search=salad)and the page number(which is unnecessary),it looks like this &page=2&page=3
Is there any good way to do this?...it would be nice if something could change only the number of page instead copying whole word.
<a href='$_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]?start=$back'><font face='Verdana' size='2'>PREV</font></a>
$query = http_build_query(array('page' => $num) + $_GET);
printf('Prev', $_SERVER['PHP_SELF'], $query);
This uses the $_GET array, which contains all the values of $_SERVER['QUERY_STRING'] in a neat array, "overwrites" the page value of that array, then re-assembles it into a URL-encoded query string.