Digital Context: Exploring Trends in Digital Publishing & Web Technology
Post Details
Adobe Spry Modifications

We primarily use Adobe’s Spry for our AJAX framework right now. These are a couple of modifications that I have made to the DataSet object itself in order to give us some new capabilities we needed for a page we were developing:

These methods can be added under the Spry.Data.DataSet object declaration in SpryData.js. They do not require any modifications to methods that already exist, nor the constructor.

The following method will allow you to create an independent copy of the DataSet without making a second asynchronus call to your handler script.

//usage: ds2 = ds1.getCopy();
Spry.Data.DataSet.prototype.getCopy = function ()
{
        var thisData   = new Array();
        var newDataSet = new Spry.Data.DataSet();
       
        thisData = this.data;
        newDataSet.setDataFromArray(thisData);
       
        return newDataSet;
};

The following method will give you a count of all the records in the dataset of which a given column or list of columns contains a certain value. For example, it could give you the number of products in the dataset that are in the series Left Behind. Please note that this method as written contains an eval statement which can be dangerous if you are passing in any user input.

//usage: count = ds.getCount(’col1,col2′,’value_in_col1_and_or_col2′);
Spry.Data.DataSet.prototype.getCount = function (inCol, inVal)
{
        var total = 0;
        if (inCol != undefined && inVal != undefined)
        {
                var colsToCount = inCol.split(‘,’);
                for (col in colsToCount)
                {
                        var rowsMatched = eval(‘this.findRowsWithColumnValues({’+colsToCount[col].replace(\’,\\‘)+’:\+inVal.replace(\’,\\‘)+’\‘});’);
                        total += rowsMatched.length;
                }
        }
       
        return total;
};

The following method returns an array of distinct values from a certain column or list of columns that reside within the dataset.

//usage: var myArrayOfValues = ds.getDistinctValues(’col1,col2′);
Spry.Data.DataSet.prototype.getDistinctValues = function (inColList)
{
        dVals = new Array();
        dDataSet = new Spry.Data.DataSet();
        colList  = inColList.split(‘,’);
        var ndx = 0;
        for (row in this.data)
        {
                for (col in colList)
                {
                        if (this.data[row][colList[col]]!=null)
                        {
                                dVals[ndx] = new Array();
                                dVals[ndx][‘newCol’] = this.data[row][colList[col]];
                                ndx++;
                        }
                }
        }
        dDataSet.setDataFromArray(dVals);
        dDataSet.distinct(‘newCol’);
        dOutArr = new Array();
        dOutVals = dDataSet.getData();
        for (x in dOutVals) dOutArr[x] = dOutVals[x][‘newCol’];
        return dOutArr;
};

Leave A Reply
Name
Mail (will not be published)
Website
Reply Text