Web hosting top - 1418 Part V . Putting JavaScript to Work
Sunday, July 22nd, 20071418 Part V . Putting JavaScript to Work colors aren t easily distinguishable in Figure 57-1, but if you open the actual example listing in IE5+/Windows on your computer, you will see the coloration. Implementation Plan Clearly all the data needed for numerous sorted and ordered views arrives in one batch in the XML island. Despite the element and node referencing properties and methods of the W3C DOM, trying to use the XML elements as the sole data store for scripts to sort the data each time would be impractical. For one thing, none of the elements have ID attributes there s no need for it in the XML stored on the server database. And even if they did have IDs, how would scripts that you desire to write for generalizability make use of them unless the IDs were generated in a well-known sequence? Moreover, after a sales rep s record is rendered in the table, how easy would it be to dive back into that record and drill down for further information, such as the name of a representative s manager? A solution that can empower the page author in this case is to use the node- walking properties and methods of the W3C DOM to assemble a JavaScript structured database while the page loads. In other words, the conversion is per formed just once during page loading, and the JavaScript version is preserved in an array (of XML records in this case) as a global variable. Any transformations on the data can be done from the JavaScript database with the help of additional powers of the language. Given that route, the basic operation of the scripting of the page is schematically simple: 1. Convert the XML into an array of objects at load time. 2. Predefine all necessary sorting functions based on properties of those objects. 3. Provide a function that rebuilds the HTML table each time data is sorted. With this sequence in mind, now look into the code that does the job. The Code Rather than work through the long document in source code order, the following descriptions follow a more functional order. You can open the actual source code file to see where the various functions are positioned. To best understand this application, seeing the how rather than the where is more important. Also, many of the code lines (even some single expressions) are too wide for the printed page and therefore break unnaturally in the listings that follow. Trust the formatting of the source file on the CD-ROM. Style sheets For the example provided on the CD-ROM, one set of style sheet rules is embed ded in the HTML document. As you can see from the rule selectors, many are tied to very specific classes of table-related elements used to render the content. In a
In case you need quality webspace to host and run your web applications, try our personal web hosting services.