A data grid is simply a DTC that ASP uses to dynamically build HTML tables. Like HTML tables, they consist of container tags. The only significant client-side difference is that data grids are really two tables, an outer table and an inner table. The real differences are on the server-side. There, the columns of a DTC data grid can be bound to a database’s recordset object. This recordset is used to build the grid rows upon the client’s request. This gives DTC data grids tremendous flexibility.
Another key element is the span tag, which is a container tag that can be used as a wrapper for other HTML elements. It enables you to apply style sheet rules to any content contained within the <span id=’xyzzy’> and </span> tags. More important, span tags provide access to outerHTML and innerHTML of the DTC data grid, which allows you to modify the content contained within each table.
causes the function plugh() to be invoked when the document is loaded and it causes the function plover() to be invoked when the document is unloaded.
Let’s start with the sortableTable class, which defines a data grid or HTML table as sortable. You create an instance of this class like this:
‘var objTBL = new sortableTable(‘myTable’);‘.
The class sortableTable has two methods: column and update. The column method defines a column as sortable and defines the type of data in it. Columns are defined as sortable by passing the column header text string to the method as the first parameter. The second parameter, which is also a string, defines a column’s data type. The valid data types for columns are string, number, currency, and date. To prevent typos, I defined the variables stString, stNumber, stCurrency, and stDate for use as parameters. The update method sets the selected columns as sortable and performs some preprocessing to speed up the sort.
How to create a sortable table
|The defined table|
Throughout the development of this utility, my goal was to avoid having to requery the server to sort the data grid by a different column. While the concept began as a way to reduce server traffic, it also serves to illustrate that there is more to client-side scripting than rollovers and pop-ups.
Want to share a Web design trick?
Send us an e-mail or post a comment below.