Spry:JsDataset
From Adobe Labs
This is a Spry code sample on how to programmatically create a data set.
This sample demonstrates one way to programatically create a dataset.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Data Set Base Class Test</title>
<script src="includes/xpath.js"></script>
<script src="includes/SpryData.js"></script>
<script>
var dsPeople = new Spry.Data.DataSet({ sortOnLoad: "lastname" });
// Create the rows of our data set.
var rowData = [
{ lastname: "Davis", firstname: "Kirk" },
{ lastname: "Miller", firstname: "James" },
{ lastname: "Wilson", firstname: "Alex" },
{ lastname: "Moore", firstname: "Albert" },
{ lastname: "Taylor", firstname: "Eric" },
{ lastname: "Anderson", firstname: "Vincent" },
{ lastname: "Thomas", firstname: "Anthony" },
{ lastname: "Lee", firstname: "John" },
{ lastname: "Smith", firstname: "Edward" },
{ lastname: "Johnson", firstname: "Neil" },
{ lastname: "Williams", firstname: "Steve" },
{ lastname: "Jones", firstname: "John" },
{ lastname: "Brown", firstname: "Joe" }
];
// Set the data in the data set equal to the rows we just created.
dsPeople.data = rowData;
dsPeople.dataHash = [];
// Now run through each row and add a ds_RowID, and add the row
// to our data hash. The key to the hash should be the ds_RowID
// for the row.
for (var i = 0; i < rowData.length; i++)
{
rowData[i]["ds_RowID"] = "ROWID-" + i;
dsPeople.dataHash[rowData[i]["ds_RowID"]] = rowData[i];
}
dsPeople.loadData();
</script>
</head>
<body>
<input type="button" value="Sort By Last Name" onclick="dsPeople.sort('lastname', 'firstname');" />
<input type="button" value="Sort By First Name" onclick="dsPeople.sort('firstname', 'lastname');" />
<div spryregion="dsPeople">
<p>Names: <span spryrepeat="dsPeople"><span spryif="{ds_RowNumber} != 0;">,</span> {firstname} {lastname}</span></p>
<table border="1">
<tr>
<th>ds_RowID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
<tr spryrepeat="dsPeople">
<td>{ds_RowID}</td>
<td>{lastname}</td>
<td>{firstname}</td>
</tr>
</table>
</div>
</body>
</html>
