For example, you might want to use the “datatable1” table from a file called datatable.html. The file might be located in a folder called data in the site’s root folder:
data/datatable.html
You could also specify a URL to the HTML file, as follows:
http://www.somesite.com/somefolder/datatable.html
<script type="text/javascript"> var datasetName = new Spry.Data.HTMLDataSet("sourcefile", "tableID"); </script>
A completed statement might look as follows:
<script type="text/javascript"> var ds1 = new Spry.Data.HTMLDataSet("data/datatable.html", "datatable1"); </script>
The statement creates a new data set called ds1 that retrieves data from the “datatable1” table in the specified HTML file. The data set has a row for each tr tag in the table, and columns to hold the items in each td tag.
You can also specify a URL as the source of the data, as follows:
var dsSpecials = new Spry.Data.HTMLDataSet("http://www.somesite.com/somefolder/datatable.html", "datatable1");
The completed example code might look as follows:
<head> ... <script type="text/javascript" src="includes/SpryData.js"></script> <script type="text/javascript" src="includes/SpryHTMLDataSet.js"></script> <script type="text/javascript"> var ds1 = new Spry.Data.HTMLDataSet("data/datatable.html", "datatable1"); </script> ... </head>
To set column types, add the setColumnType() data set method to the head tag of your document, after you’ve created the data set, as follows (in bold):
<script type="text/javascript"> var ds1 = new Spry.Data.HTMLDataSet("data/datatable.html", "datatable1"); ds1.setColumnType("price", "number"); </script>
In the example, the expression calls the setColumnType method on the ds1 data set object, which you’ve already defined. The setColumnType method takes two parameters: the name of the data set column to retype (in this example, "price") and the desired data type ("number").
After you’ve created the data set, create a dynamic region so that you can display the data.