I. Problem Description
How to control the pages of a report by up and down keys in our keyboard just like we presenting a PowerPoint?
II. Solution
Each key in the keyboard has a unique key code. With JavaScript, we can obtain the key code of the pressed key, judge whether it is a up/down key, and then make the report jump to the previous/next page.
III. Example
Select Template > Web Attributes. Choose Pagination Preview, checkIndividually set for the template, and add a Loading End event.
JS code:
$(document).bind('keydown', function(e) { //Get key press event
var key = window.event ? e.keyCode : e.which; //Get key code
//alert(key);
if (key.toString() == "33"|| key.toString() == "37" || key.toString() == "38") {
contentPane.gotoPreviousPage(); //Jump to the previous page
}
else if (key.toString() == "32" || key.toString() == "34"|| key.toString() == "39" || key.toString() == "40") {
contentPane.gotoNextPage(); //Jump to the next page
}
})
Key code table:
Key | Key code |
---|---|
Space | 32 |
Page Down(PgDn) | 34 |
Left Arrow(←) | 37 |
Up Arrow(↑) | 38 |
Right Arrow(→) | 39 |
Down Arrow(↓) | 40 |
Save report and select Pagination Preview, if click Page Up(PgUp), Left Arrow(←) or Up Arrow(↑), the page will jump to the previous page.
Oppositely, if click Space, Page Down(PgDn), Right Arrow(→) or Down Arrow(↓), page can jump to the next page.