The main aim of this article is to see how you can compare subtotals using a 3D HTML recordset. Subtotals result from aggregate functions such as Sum, Avg and Count on database tables. This article is the third part of a four-part series.
Comparing Subtotals Using a 3D HTML Recordset - Code Explanation (Page 4 of 4 )
We have a recordset that has a 3D table of 3 horizontal planes and 4 vertical planes.
Now, click the “Scroll Inward” button repeatedly and you should see the contents of the different vertical planes; stop when you do not see any subtotal.
Now click the “Determine Total per Category per Column” button. The name of the button tells its use. You should see the overall totals arrived at by summing across the vertical planes. There are 4 V planes in the recordset; this is the last. It comes empty from the database engine. Its values are the results of calculations.
Refresh the page to reset the data. This is for convenience. You should be seeing the figures of the first vertical plane.
Click the “Determine Total per Category per Column” button. The overall totals will be calculated and put in their corresponding positions in the last V plane. At this point you are not seeing the results.
Click the “Scroll Inward” button repeatedly until you see the results (last V plane).
The Code
The recordset is a 3D HTML Table element.
Inspect the way I wrote the code for the table and also note the way I gave the IDs for the table element.
The fundamental statement for the JavaScript code is
document.getElementById(TID).rows[0].cells[k].
This returns a reference to a cell in the one-row table whose id is TID. Recall that each of these one-row tables has only one row. So to access the row you need only the index 0. A particular cell in the row is accessed with the index variable k.
In a function loop, different values of TID have to be formed in order to access the different tables and their cells.
Now, the “innerHTML” attribute may not return figures as you see them in a table cell. So you should use the parseFloat(value) function so that what is returned is the figure you saw.
If you have read the articles titled “Building a 3D HTML Table” and “Using a 3D HTML Table as a Recordset" that I wrote, then the complete code here should be self-explanatory.
I hope this article has made you appreciate one good use of a 3D recordset.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.