Data sets support both destructive and non-destructive filtering.
Before using either method of filtering, supply a filter function that takes a data set, row object and rowNumber. This function is invoked by the data sets filtering methods for each row in the data set. The function must return either the row object passed to the function, or a new row object, meant to replace the row passed into the function. For the function to filter out the row, it should return a null value.
The data set's destructive filter method is filterData(). This method actually replaces or discards the rows of the data set. The only way to get the original data back is to reload the XML data of the data set.
... // Filter out all rows that don't have a path that begins // with the letter 's'. var myFilterFunc = function(dataSet, row, rowNumber) { if (row["@path"].search(/^s/) != -1) return row; // Return the row to keep it in the data set. return null; // Return null to remove the row from the data set. } dsPhotos.filterData(myFilterFunc); // Filter the rows in the data set.
The filter function remains active, even when loading XML data from another URL, until you call filterData() with a null argument. Call filterData() with a null argument to uninstall your filter function.
dsPhotos.filterData(null); // Turn off destructive filtering.
The data set's nondestructive filter method is filter(). Unlike filterData(), filter() creates a new array of rows that reference the original data. As long as the filter function does not modify the row object passed into it, you can get the original data back by calling filter() and passing a null argument. Use the nondestructive filter() method to filter the rows in a data set.
var dsPhotos = new Spry.Data.XMLDataSet("/photos.php?galleryid=2000", "/gallery/photos/photo"); ... // Filter out all rows that don't have a path that begins // with the letter 's'. var myFilterFunc = function(dataSet, row, rowNumber) { if (row["@path"].search(/^s/) != -1) return row; // Return the row to keep it in the data set. return null; // Return null to remove the row from the data set. } dsPhotos.filter(myFilterFunc); // Filter the rows in the data set.
To get the original data back, call filter() and pass a null argument
dsPhotos.filter(null); // Turn off non-destructive filtering.