Spry built-in variables for Datasets

This post is more than 2 years old.

This is mainly for my own reference - but as I always have trouble finding it - I thought I'd share. When working with Spry datasets, you have access to both the data in the set (obviously) as well as a set of built-in variables prefixed by ds_. The variables you can use:

  • ds_RowID - This is the id of a row in the data set. This id can be used to refer to a specific record in the data set. It does not change even when the data is sorted.
  • ds_RowNumber - This is the row number of the "current row" of the data set. Within a loop construct, this number reflects the position of the row currently being evaluated.
  • ds_RowNumberPlus1 - This is the same as ds_RowNumber except that the first row starts at index 1 instead of index 0.
  • ds_RowCount - This is the number of rows in the data set. If there is a non-destructive filter set on the data set, this is the total number of rows after the filter is applied.
  • ds_UnfilteredRowCount - This is the number of rows in the data set before any non-destructive filter is applied.
  • ds_CurrentRowID - This is the id of the "current row" of the data set. This value will not change, even when used within a looping construct construct.
  • ds_CurrentRowNumber - This is the row number of the "current row" of the data set. This value will not change, even when used within a looping construct.
  • ds_SortColumn - This is the name of the column last used for sorting. If the data in the data set has never been sorted, this will output nothing (an empty string).
  • ds_SortOrder - This is the current sort order of the data in the data set. This data reference will output the words "ascending", "descending", or nothing (an empty string).
  • ds_EvenOddRow - This looks at the current value of ds_RowNumber and returns the string "even" or "odd". This is useful for rendering alternate row colors.

The text above was ripped from: http://labs.adobe.com/technologies/spry/articles/data_set_overview/

I'm thinking of creating a Spry cheat sheet to contain stuff like this and other tips that may be useful for development. If folks have some ideas for what to include, let me know by posting here.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Ed posted on 11/1/2006 at 11:16 PM

Cool, I actually just used ds_RowCount to get half of the problem I was having with tabulating data within an XML node. Now I just need to get the semantics down of how to count the value within the node and display it at the bottom of the page ..

Comment 2 by Lola Lee Beno posted on 11/2/2006 at 6:53 PM

How about including techniques to get it working with MG:U? I'm going to be looking into this, and I need to have basic steps outlined so I can at least get started off on the right foot.

Comment 3 by Raymond Camden posted on 11/2/2006 at 7:22 PM

I think that may be a bit too long for a FAQ - but I could easily point to my blog article on it. You did see that article, right?

Comment 4 by Lola Lee Beno posted on 11/2/2006 at 8:07 PM

Yes, I dd see that. By the way, when I click on Print, the text comes out as centered, not aligned at the left or justified.

Comment 5 by Bruce Phillips posted on 11/2/2006 at 11:23 PM

One thing I'm trying to do is have one entry on my Spry blog that lists everything the Spry currently includes. You can check it out here:


I know that Spry is in Alpha/Beta/Pre-Release, but I'm trying to keep track of what we can use Spry for. If you have any ideas of stuff I'm missing under Spry Data Set, Effects, or Widgets let me know.


Comment 6 by Chris posted on 11/16/2006 at 5:20 PM

Hi guys.

I searched the net and couldn't find a solution for my problem, so I decided to ask the pro's.

How do I get the current row number of all children of a dataset element.

I use spry:repeat to repeat elements of a dataset and spry:repeatchildren to repeat the children of the elements for each row.
I want to use ds_EvenOddRow to render alternate row colors for the children of the elements, but I have no clue how to do that.
Can anyone help?

Thanx in advance,

Comment 7 by Raymond Camden posted on 11/16/2006 at 5:27 PM

ds_evenevenoddrow simply outputs even or odd, so you could make CSS items named mydataeven and mydataodd, then do this in your html, class="mydata{ds_evenoddrow}". Now I've never used that before with children so I'm not sure what ds_evenoddrow will do. The simplest thing is to just output it! Just add the token to your html and what do you see?

Comment 8 by Chris posted on 11/16/2006 at 6:05 PM

Thanx for the fast reply! :D

That is what I did... the CSS item renders the main elements but not the children.

The output looks like this:

1 MainElement
1 Child (class="mydataeven")
2 Child (class="mydataeven")
3 Child (class="mydataeven")
2 MainElement
1 Child (class="mydataodd")
2 Child (class="mydataodd")

And this is what I would like to have:
1 MainElement
1 Child (class="mydataeven")
2 Child (class="mydataodd")
3 Child (class="mydataeven")
2 MainElement
1 Child (class="mydataeven")
2 Child (class="mydataodd")

If I could get the row number of the child-elements, I could use spry:if to check if the row number is even or odd, but I don't know how.

Comment 9 by Raymond Camden posted on 11/16/2006 at 6:41 PM

I was worried about that. I'll do some checking on it. Think you can send me your xml and html in a simple format I can use to test?

Comment 10 by Chris posted on 11/17/2006 at 4:06 PM

Hi Ray,

sorry for the late answer.
I had to adapt the code to a simple example (we're working with MG/Reactor/ColdSpring). I'm only the designer and I'm not sure if everything is coded correctly but it should reflect the original application.

At least I could partially figure out where the problem is - it's the spry:region (when having more than one dataset).
Whereto can I send the files?

Comment 11 by Raymond Camden posted on 11/17/2006 at 9:07 PM

Send it to ray, then the at symbol, than camdenfamily dot com.

Comment 12 by Christopher Walker posted on 6/5/2008 at 8:16 PM

Hey Ray:

I'm working on a spry table which uses a xml dataset. Additionally, I'm using ColdFusion Report Builder to create a PDF or an Excel file (customer choice) using the screen output data. My boss loves it but now he wants to output the cfr based upon the way the customer orders the columns. So what I'm currently trying to do is pass the {ds_SortColumn} {ds_SortOrder} into the query as a ORDER BY statement. I'm having some issues, if anyone has any ideas I'd love to hear it. In the mean time I'll keep you informed.

Comment 13 by Christopher Walker posted on 6/5/2008 at 8:34 PM

Big DUH! It was easier than I thought. I was thinking this wouldn't work unless that page was redrawn, but that's not the case.

<a href="/reports/blah_blah.cfr?sortOrder={ds_SortOrder}&column={ds_SortColumn}" target="_blank">

And the query:
<cfif ((isDefined(url.column) and (trim(url.column) neq '')) and (isDefined(url.sortOrder) and (trim(url.sortOrder) neq '')))
<cfset ORDER = 'Order By' & '#url.column#' & '#url.sortOrder#'>
<cfset ORDER = ''

Comment 14 by Raymond Camden posted on 6/5/2008 at 9:48 PM

Glad you got it.

Comment 15 by Christopher Walker posted on 6/6/2008 at 6:21 PM

Does anyone have a quick and dirty way to assign a value to ds_SortOrder and ds_SortColumn on the inital load?

E.g.: ds_SortOrder == 'ascending'
ds_SortColumn == 'id_info'

I know it a bit more complcated than that as the info appears to be stored in a JSON object or XML dataset depending on the developer's choice. In my case I'm consuming XML data.

Comment 16 by Raymond Camden posted on 6/6/2008 at 6:34 PM

Oddly the API only provides getMethods, not set. Let me ping the Spry guys.

Comment 17 by Kin Blas posted on 6/9/2008 at 8:28 PM

You want to use the sortOnLoad and sortOrderOnLoad data set constructor options:


--== Kin ==--

Comment 18 by Bill posted on 11/3/2008 at 7:15 AM

Anyone got any ideas how I can get the SpryJSONDataSet to load a JSON object (js variable) instead of from a url?

Comment 19 by Raymond Camden posted on 11/4/2008 at 2:20 AM

XML datasets supporting loading via a JS object as opposed to an XHR request, so I'm pretty sure JSON datasets do as well. Have you scanned the API docs?