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.
Archived Comments
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 ..
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.
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?
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.
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:
http://www.brucephillips.na...
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.
Bruce
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,
Chris
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?
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.
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?
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?
Send it to ray, then the at symbol, than camdenfamily dot com.
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.
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#'>
<cfelse>
<cfset ORDER = ''
</cfif>
SELECT *
FROM SOMETABLE
#ORDER#
Glad you got it.
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.
Oddly the API only provides getMethods, not set. Let me ping the Spry guys.
You want to use the sortOnLoad and sortOrderOnLoad data set constructor options:
http://labs.adobe.com/techn...
--== Kin ==--
Anyone got any ideas how I can get the SpryJSONDataSet to load a JSON object (js variable) instead of from a url?
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?