Click to See Complete Forum and Search --> : Page Break and Dynamic Table
sharapov
05-30-2003, 03:53 PM
Hello,
I am retrieving data from the database and displaying it inside HTML table. What I want to do is insert a page break after every sixth row of the table (i.e. page break after row 6, 12, 18, etc.) by doing something like this: <tr style="page-break-after: always;">. Is it possible to do it with JavaScript? Keep in mind that since data is generated from database I can't assign ID's to the table's rows. Is there any other way?
Thanks.
khaki
05-30-2003, 04:14 PM
hi sharapov...
how are you pulling the data? ASP?
If so... just use VBScript to do a record count, and place a conditional at the <tr> to either write your "page break <tr>" or a regular <tr> tag based on whether the current record is 6, 12, 18, etc.
If you are using PHP (or whatever else)... I'm sure that it is possible to do the same with those as well (I guess :rolleyes: ).
;) k
sharapov
05-30-2003, 04:16 PM
khaki,
I use PHP. Although I can assign page breaks with PHP when table is generated, I don't want to do it because my users interact with table by removing certain rows. After row is removed I don't want to send page back to the server to recalculate page break position, I want to do it only on the client's side using JavaScript.
khalidali63
05-30-2003, 04:17 PM
I am sure you must have control over the contents where you create the tbales? do you?..
If yes then its hsould not be a problem doing this.you can count rows and after every six row add the page break.
The second solution is dom based,I know page break after works with NS for sure,
Here it goes.
var rows = document.getElementByTagName("tr");
Now you have all the tr elements on the page.
now go through them and add an element
presuming you call the Process function with onload="Process()" in the body tag
<script type="text/javascript">
function Process(){
var rows = document.getElementsByTagName("tr");
var len = rows.length;
for(var x=0;x<len;x++){
var ctr= x+1;
if(ctr%6==0){
createPageBreak(x,rows[x]);
}
}
function createPageBreak(x , row){
row.setAttribute("STYLE","page-break-after:always;");
}
}
//-->
</script>
</head>
<body onload="Process();">
sharapov
05-30-2003, 05:17 PM
khalidali63,
Thank you for your help. It looks like it will work!
khalidali63
05-30-2003, 06:01 PM
You are welcome...I have used page breaks in NS..that I know..and now after I posted the above message I actually tested it against IE6+ and it works on that too..so we are all happy:D