Home Answers Viewqa Design-concepts-design-patterns Javascript Fixed Header in A table

 
 


debasis
Javascript Fixed Header in A table
2 Answer(s)      2 years and 10 months ago
Posted in : Design concepts & design patterns

Dear Sir,
Thank you for your help.It is a great web site with a lot of help
Cheers & Thank You again.
My question is while querying some data and placing it in a table i have as many as 40 columns with many rows.when i am scrolling down data in the table the header gets lost.While analysing data one cant identify the coloumns to respective name.I want that header to be fixed,even after am scrolling 20000 data.But header with the name should be fixed and data to be scrolled down.my table header code is like this .you can use this or by giving single <td> to give coloumn name.


tblHeader = "<tr><th> Sl. No.</th><th>DTR No</th><th>Transformer Rating</th><th>Manufacturer Name</th>"+
"<th>Year of Manufacturer</th><th>Manufacturer Sl. No.</th><th>P.O. No.</th><th>Lot No</th></tr>";


<table class = "formfields" border = "1" align="center" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111">
<%=tblHeader %>

After this how and what code should i give for a fixed header.Thank You

Regards
Debasis Mohapatra
View Answers

August 5, 2010 at 1:05 PM


Hi Friend,

You can do paging.

Try the following code:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%!
public int nullIntconvert(String str){
int num=0;
if(str==null) {
str="0";
}
else if((str.trim()).equals("null")) {
str="0";
}
else if(str.equals("")) {
str="0";
}
try{
num=Integer.parseInt(str);
}
catch(Exception e) { }
return num;
}
%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;

int showRows=10;
int totalRecords=10;
int totalRows=nullIntconvert(request.getParameter("totalRows"));
int totalPages=nullIntconvert(request.getParameter("totalPages"));
int iPageNo=nullIntconvert(request.getParameter("iPageNo"));
int cPageNo=nullIntconvert(request.getParameter("cPageNo"));

int startResult=0;
int endResult=0;
if(iPageNo==0){
iPageNo=0;
}
else{
iPageNo=Math.abs((iPageNo-1)*showRows);
}
String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();
String query2="SELECT FOUND_ROWS() as cnt";
ps2=conn.prepareStatement(query2);
rs2=ps2.executeQuery();
if(rs2.next()) {
totalRows=rs2.getInt("cnt");
System.out.println(totalRows);
}
%>
<html>
<h3>Pagination of JSP page</h3>
<body>
<form>
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="showRows" value="<%=showRows%>">
<table width="100%" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Marks</td>
<td>Grade</td>
</tr>
<%
while(rs1.next()){
%>
<tr>
<td><%=rs1.getInt("rollNo")%></td>
<td><%=rs1.getString("name")%></td>
<td><%=rs1.getInt("marks")%></td>
<td><%=rs1.getString("grade")%></td>
</tr>
<%
}
%>
<%
try{
if(totalRows<(iPageNo+showRows)) {
endResult=totalRows;
}
else{
endResult=(iPageNo+showRows);
}
startResult=(iPageNo+1);
totalPages=((int)(Math.ceil((double)totalRows/showRows)));
}
catch(Exception e){
e.printStackTrace();
}
%>
<tr>
<td colspan="3">
<div>

August 5, 2010 at 1:05 PM


continue...

<%
int i=0;
int cPage=0;
if(totalRows!=0) {
cPage=((int)(Math.ceil((double)endResult/(totalRecords*showRows))));
int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
if((cPage*totalRecords)-(totalRecords)>0){
%>
<a href="pagination.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="pagination.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%>-<%=endResult%>Total Rows<%=totalRows%> </b>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
try{
if(ps1!=null){
ps1.close();
}
if(rs1!=null){
rs1.close();
}

if(ps2!=null){
ps2.close();
}
if(rs2!=null){
rs2.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>

The above jsp page is named as 'pagination.jsp'.

It will be helpful for you.
Thanks









Related Pages:
Javascript Fixed Header in A table - Design concepts & design patterns
Javascript Fixed Header in A table  Dear Sir, Thank you for your... name.I want that header to be fixed,even after am scrolling 20000 data.But header with the name should be fixed and data to be scrolled down.my table header
Fixed Header - Design concepts & design patterns
scrolling down data in the table the header gets lost.While analysing data one cant identify the coloumns to respective name.I want that header to be fixed,even after am scrolling 20000 data.But header with the name should be fixed and data
table header
table header  how set the header to the TableModel
Fixed size tables
Fixed size tables  Can anyone help me in creating a fixed size table in mysql database
table?
table?  Hi, how could i make a table in javascript, which would look... ... Where first two columns are fixed, and last two need mathematical calculations? I can't figure out, how to construct a table,with two fixed columns, one that reads
No Max-height Fixed
No Max-height Fixed      ... of a Textarea with minimum fixed height but no max height fixed. Steps to develop the Auto generate of a Textarea  with minimum fixed height but no max height fixed
JavaScript createTHead method
;    In JavaScript we can create and add table header... header.    document.getElementById('table') .createTHead(); We can also add some style and color to this table header. Here is the full
panelGrid header
/tomahawkpanelGridtag.shtml I have question how we can generate data table in the following
javascript - Design concepts & design patterns
for fixed header.Means,in a dispaly table in which am querying the results from database,header should be fixed,but data should be scrollable.e.g in a employee table name,designation,address header should be fixed and records should
With Fixed Max-Height
With Fixed Max-Height      ...; textarea  with fixed Max-Height. Steps to develop the Auto generate of a Textarea with fixed Max-Height. Step 1:       Create a new file
JavaScript deleteTHead method
page with the use of JavaScript method similarly we can delete and create Table header with the use of JavaScript method deleteTHead() of the table object. In this example of JavaScript methods we have deleted the table header by getting
JavaScript createTFoot method
JavaScript createTFoot method       We can add header and footer also to the table by using...; <thead> <th colspan="2"> Information table Header <
Struts2 freeze header
Struts2 freeze header  Sir, I am using display table to list my table in details in database in jsp that i am using title i need to freeze the title in that page while scrolling its also scrolling because my requirement
HTML Table in javascript
HTML Table in javascript  hi all, how to add last row with sum in table using javascript
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
JavaScript - JavaScript Tutorial
header and footer also to the table by using the JavaScript in a similar manner...; JavaScript createTHead method In JavaScript we can create and add table header... header with the use of JavaScript method deleteTHead() of the table object
javaScript
javaScript  . Print a table like below in JAVASCRIPT 5 x 1 = 5 5 x 2 = 10 ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦. 5 x 20 = 100
JavaScript deleteTFoot method
then we can delete this table footer by calling the JavaScript method...="400"> <thead> <th colspan="2"> Information table Header <... JavaScript deleteTFoot method   
JavaScript sort table
JavaScript sort table..., we are going to sort the table using the JavaScript. To sort the table, we... type="text/javascript" src="sort.js"></SCRIPT> <TABLE WIDTH="55
JavaScript Show Hide table
JavaScript Show Hide table... the JavaScript. In the given example, we have created a table. The method...='javascript:hideTable();' value='hide'> <table id='table' border=1>
JavaScript Hide Table Rows
JavaScript Hide Table Rows...; In this section, you will learn how to hide table rows using JavaScript... Table Row</h2> <script language="javascript"> var hide
JavaScript Hide Table Column
JavaScript Hide Table Column...; In this section, we are going to hide a table column using JavaScript. In the given example, we have created a table consisting of four columns. Here we
Jaret Table
Jaret Table         The jaret table is a custom drawn table for the SWT gui toolkit... to the native SWT table. This might solve a lot of the most common problems. See
JavaScript add row dynamically to table
JavaScript add row dynamically to table  ... to the table by adding a pair of  <TR></TR> tags. If we want to add row to a table dynamically then we can also do this with the JavaScript code
Fixed Values
Fixed Values If you want to supply any fixed value to the element then "... automatically but is fixed and can not be changed. Whenever the element is used in the document it has its fixed value and user can not provide any other
JavaScript add row to table
JavaScript add row to table      ... table using JavaScript. You can see in the given example, we have created a table...="javascript:addRow('table')">Add row</button> </html>
Request header display in a jsp page
Request header display in a jsp page  ... to display request header information in a jsp page. When user request... to a jsp. In this example, request_header_jsp.jsp is used to display header
header files
header files   do you have a all header files of java
header() in php
header() in php  hello, Use of header() in php?   hello, header() is used for redirect the page.if you want to redirect one page to another we can use
Header file
Header file  when we use, Scanner input=new Scanner(System.in); this statement in a java program,which header filemust be imported to the program?   Hi Friend, Import the package java.util.*; Thanks
swings header
. i need logic for this program . i want to apply this to window header part
javaScript+Html
javaScript+Html  print("code sample");(Use ExtJS 3 or 4) and create following (HTML, Javascript,ExtJS) a. Create a single page application divided into 4 sections - Top Header, Footer,Left Navigation (Tree), Center Panel
How to set the pdfptable as pdf page header when generating the pdf from jsp page. - JSP-Servlet
How to set the pdfptable as pdf page header when generating the pdf from jsp page.  how to set the pdfptable column headers as a header...(PageSize.A4.rotate(), 0, 0, 20, 20); PdfPTable table=new PdfPTable(2
php header syntax
php header syntax  What is the correct syntax of PHP Header
Sigma grid -- Ajax-enabled JavaScript grid
Sigma grid -- Ajax-enabled JavaScript grid   ... AJAX editable data grid, written in pure javascript for displaying and inline editing data in a scrollable and sortable table. It is a very powerful data
Fixed Value check using struts validator framework
Fixed Value check using struts validator framework  Hi All, can anyone tell me how to use struts validator framework for fixed value check. eg. country='India'; Thanks in advance
Javascript code
Javascript code  Dear Sir, Again i am in need of your small help.I... the table.I want to align all the table data in one page.My table structure......(30 rows) 1 2 233 All the data in the table space 4 45 5 5 5.. What
Java Hash table
Java Hash table   Hi I have to create code to allow the insertion of a sequence of numbers into a hash table,using a fixed size hash table. Then i... of numbers; insert these into the hash table. Can anyone give me any help
javascript - Ajax
click on particular image of slide show in javascript. i used href tag but it does not work so i m posting my javascript code here below. note: in the head section the images are coming from asp script database table ok
Javascript - JDBC
Javascript   Hi, I am doing a project in healthcare domain... then some records from database table should be displayed out. I am using jsp and javascript I want to write the event handling code in another jsp page .so
http header content length
http header content length  How to check the request header content length in HTTP
Setting the Column Header in JTable
. getTableHeader(): This method takes table header from the JTable. Here is the code... Setting the Column Header in JTable   ... in setting the column headers in JTable. First of all, program creates a table that has
javascript - JavaMail
); // Set the RFC 822 "From" header field using the // value...(to)); // Set the "Subject" header field. message.setSubject("hi
Imp-HTML Table Sorting
of HTML table sorting where sorting happenes whenever user clicks on column header...Imp-HTML Table Sorting   Hi, I am working on a project and as per requirement from client i have to sort a table based on the ID Column. I want
alignment for header and footer
alignment for header and footer  header and footer alignment is not fit like footer is not fit in bottom some white space is there in jsf, what to do
Table Maintenance Statements
Table Maintenance Statements       In this section we are covering the topics like ANALYZE TABLE, BACKUP TABLE, CHECK TABLE, CHECKSUM TABLE, OPTIMIZE TABLE, REPAIR TABLE, RESTORE
javascript validation
javascript validation  my problem is following code is my form i want.... <html> <script src="combovalidate1.js" type="text/javascript" language="javascript"> </script> <body> <form name="form
Javascript DOM
Javascript DOM  I'm getting into client-side scripting using javascript. I am attempting to build a football team fixture application. The user...;/title> <script language="javascript" type="text/javascript" src
Javascript & jsp
Javascript & jsp  Dear Sir, I have a table which has records...*"%> <html> <head> <script type="text/javascript"> function...="employee"> <br><br> <table > <div id="mydiv"><
javascript - Ajax
javascript  Hi, I want to create the help.jsp I created 1 table and inside the table i created 2 s one for the contents of Help. and other is to display the content. The structure of the contents is 1. Login 2. DashBoard

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.