04.02.2013 Views

Spry User Guide - Support - Adobe

Spry User Guide - Support - Adobe

Spry User Guide - Support - Adobe

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo");<br />

...<br />

dsPhotos.sort("@path", "toggle"); // Toggle the Sort order of the rows of the data set using<br />

the "@path" column.<br />

To have the data in the data set sorted automatically whenever data is loaded, specify the column to sort by and the<br />

sort order to use as an option to the data set constructor. Use the "sortOnLoad" option to the data set constructor<br />

to specify a column to sort by. In the following example, the data set automatically sorts in descending order by using<br />

the data in the @path column.<br />

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo", { sortOnLoad: "@path", sortOrderOnLoad: "descending" });<br />

By default, all values in the data set are treated as text. This can be problematic when sorting numeric or date values.<br />

You can specify the data type for a given column by calling the setColumnType() method.<br />

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo");<br />

dsPhotos.setColumnType("@width", "number");<br />

dsPhotos.setColumnType("@height", "number");<br />

...<br />

dsPhotos.sort("@width"); // Sort the rows of the data set using the "@width" column.<br />

Current supported data types are "number", "date", and "string".<br />

Set or change current row<br />

Each data set maintains the notion of a current row.Bydefault,thecurrentrowissettothefirstrowinthedataset.<br />

To change the current row programmatically, call the setCurrentRowNumber() method and pass the row number<br />

of the row you want to make the current row. The index of the first row is always zero, so if a data set contains 10<br />

rows, the index of the last row is 9.<br />

❖ Use setCurrentRowByNumber() or setCurrentRow() to change the current row:<br />

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo");<br />

...<br />

dsPhotos.setCurrentRowNumber(2); // Make the 3rd row in the data set the current row.<br />

Each row in the data set is also assigned a unique ID that allows you to refer to a specific row in the data set even<br />

after the order of the rows in the data set change. You can get the ID of a row by accessing its "ds_RowID" property.<br />

You can also change the current row by calling setCurrentRow() and passing the row ID of the row to make the<br />

current row.<br />

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo");<br />

...<br />

var id = dsPhotos.getData()[2]["ds_RowID"]; // Get the ID of the 3rd row.<br />

...<br />

dsPhotos.setCurrentRow(id); // Make the 3rd row the current row by using its ID.<br />

Remove duplicate rows<br />

❖ Use the distinct() method to remove duplicate rows in a data set:<br />

SPRY<br />

<strong>User</strong> <strong>Guide</strong><br />

124

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!