Displaying Script Output by Using the Tabular Data Control

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The script shown in Listing 17.7 provides a quick and easy way to display data. Like most standard Web pages, however, it does not allow you to manipulate that data in any way. The data cannot be sorted; instead, it is displayed in the order it is returned by WMI. Sorting is not the only limitation of this script; in addition, you cannot retrieve information for all the services on a computer and then choose to display only those services that are running. To filter the data display, you would need to edit and rerun the script so that it returns only the services that are running. To again look at all the services, you would need to re-edit and rerun the script.

The tabular data control (an ActiveX control that is installed with Internet Explorer) provides a way to display data in tabular format. But the tabular data control does more than just make it quick and easy to display data in a table. By adding a few lines of code, you can sort this data any way that you want; for example, you can sort a list of services by name, by status, by the service account under which they run, or by any other property in your data set. Likewise, you can also filter the data dynamically; for example, you can show all the services, dynamically hide all the services that are not running, and then dynamically show all the services again. This can all be done without having to refresh the page or requery the data set.

With the tabular data control, you do the following:

  1. Save the data to be displayed to a text file (typically a comma-separated values file). The first row in the text file is the field headers; subsequent rows represent the field data for a record.

    For example, a text file containing service information might look like this:

    Service Name,Service Type,Service State

    Alerter,Share Process,Running

    AppMgmt,Share Process,Running

    Ati HotKey Poller,Own Process,Stopped

  2. Insert the tabular data control in the Web page. As part of this process, indicate the path to the text file containing the data to be displayed. The code for inserting the tabular data control looks similar to this (the individual parameters are explained in Table 17.5):
    <OBJECT id="serviceList" CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">    <PARAM NAME="DataURL" VALUE="c:\scripts\service_list.csv">         <PARAM NAME="UseHeader" VALUE="True">    <PARAM NAME="TextQualifier" VALUE=","> </OBJECT> 
  3. Create the header row for the table.
  4. Create the initial data row for the table. Instead of inserting data into this row, you set the Datafld (data field) property for each cell to correspond to a particular field in the text file. If your text file includes the field headers Service Name, Service Type, and Service State, you would set the Datafld property for the first cell in the table to Service Name, the Datafld property for the second cell to Service Type, and the Datafld property for the third cell to Service State.

    The actual HTML code might look like this:

    <TR> <TD><DIV datafld="Service Name"></DIV></TD> <TD><DIV datafld="Service Type"></DIV></TD> <TD><DIV datafld="Service State"></DIV></TD> </TR> 

    After you have created the initial row, all subsequent rows in the table are created dynamically when the text file is read. Setting up one row in the table results in multiple rows (one for each line in the text file) being displayed when the Web page is opened.

You can also use other HTML formatting in creating your table. For example, if you want to display the Service Name in bold, you can insert the HTML tag for bold (<B>):

<TD><B><DIV datafld="Service Name"></DIV></B></TD> 

The tabular data control supports the properties shown in Table 17.5.

Table 17.5   Tabular Data Control Properties

PropertyDescription
DataURLSpecifies the location of the data file. This can be either a URL or a file path. For example, this parameter sets the DataURL to C:\Scripts\Service_List.csv:

<PARAM NAME="DataURL"VALUE="c:\scripts\service_list.csv">

FieldDelimIdentifies the field delimiter, the character used to mark the end of a field in the data file. By default, this is the comma. To set the field delimiter to another character, use the HTML value for that character. This example sets the field delimiter to the tab character:

<PARAM NAME = FieldDelim VALUE = "&#09">

TextQualifierSpecifies characters that might surround data fields in a text file. For example, in this file, the field delimiter is the comma, and the text qualifier is the quotation mark:

Ken, Myer, "Human Resources"

RowDelimIdentifies the character used to mark the end of each row of data. The default value is the newline character (NL), which simply means that new lines are denoted by pressing ENTER at the end of the previous line.
UseHeaderSpecifies whether the first line of the data file contains field headers. The default value is False.
SortSpecifies the sort order for the table. For more information, see "Sorting Data by Using the Tabular Data Control" later in this chapter.
FilterProvides the ability to display a subset of records based on specific criteria. For more information, see "Filtering Data by Using the Tabular Data Control" later in this chapter.

Scripting Steps

Listing 17.11 contains a Web page that displays script output by using the tabular data control. To carry out this task, the Web page must include the following:

  1. The starting <HTML> and <BODY> tags.
  2. An <OBJECT> tag used to insert the tabular data control. You must specify an id for the control as well as this CLASSID:

    clsid:333C7BC4-460F-11D0-BC04-0080C7055A83.

    In addition, specify the following parameters:

    • DataURL, along with the path to the comma-separated-values file.
    • UseHeader, indicating that the first row in the comma-separated-values file contains header information.
    • TextQualifier, indicating that the comma is used to separate items within each row of the text file.
  3. An <H2> tag used to provide a heading for the page.
  4. A table, with the datasrc set to #serviceList (the id assigned to the tabular data control, prefaced by the pound sign [#]). This means that the table will derive its data from the tabular data control. If your id is serviceInformation, the datasrc is set to #serviceInformation.
  5. A <THEAD> and <TR> tag to mark the first row in the table. Three <TD> tags are used to indicate individual columns in the table:
    • Computer
    • Service
    • Status
  6. A <TBODY> and <TROW> tag used to delineate the data columns. Each column must specify a datafld used in the header row of the text file:
    • System Name
    • Display Name
    • Service State
  7. Ending tags for the table, body, and HTML.

Listing 17.11   Displaying Data by Using the Tabular Data Control

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 
<HTML> <BODY> <OBJECT id="serviceList" CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">    <PARAM NAME="DataURL" VALUE="c:\scripts\service_list.csv">    <PARAM NAME="UseHeader" VALUE="True">    <PARAM NAME="TextQualifier" VALUE=","> </OBJECT> <H2>Current Service Status</H2> <table border='1' width='100%' cellspacing='0' datasrc=#serviceList> <THEAD><TR> <TD>Computer</TD> <TD>Service</TD> <TD>Status</TD> </TR> </THEAD> <TBODY> <TR> <TD><B><DIV datafld="System Name"></DIV></B></TD> <TD><DIV datafld="Display Name"></DIV></TD> <TD><DIV datafld="Service State"></DIV></TD> </TR> </TBODY> </TABLE> </BODY> </HTML>

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net