Twitter: raymondcamden


Address: Lafayette, LA, USA

Spry built-in variables for Datasets

11-01-2006 8,158 views 19 Comments

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.

19 Comments

  • Ed #
    Commented on 11-01-2006 at 12: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 ..
  • Lola Lee Beno #
    Commented on 11-02-2006 at 7:53 AM
    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.
  • Commented on 11-02-2006 at 8:22 AM
    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?
  • Lola Lee Beno #
    Commented on 11-02-2006 at 9:07 AM
    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.
  • Commented on 11-02-2006 at 12: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:

    http://www.brucephillips.name/blog/index.cfm/2006/...

    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
  • Commented on 11-16-2006 at 6:20 AM
    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
  • Commented on 11-16-2006 at 6:27 AM
    dsevenevenoddrow simply outputs even or odd, so you could make CSS items named mydataeven and mydataodd, then do this in your html, class="mydata{dsevenoddrow}". 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?
  • Commented on 11-16-2006 at 7:05 AM
    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.
  • Commented on 11-16-2006 at 7:41 AM
    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?
  • Commented on 11-17-2006 at 5:06 AM
    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?
  • Commented on 11-17-2006 at 10:07 AM
    Send it to ray, then the at symbol, than camdenfamily dot com.
  • Commented on 06-05-2008 at 11:16 AM
    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 {dsSortColumn} {dsSortOrder} 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.
  • Commented on 06-05-2008 at 11:34 AM
    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/blahblah.cfr?sortOrder={dsSortOrder}&column={dsSortColumn}" 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#
  • Commented on 06-05-2008 at 12:48 PM
    Glad you got it.
  • Commented on 06-06-2008 at 9:21 AM
    Does anyone have a quick and dirty way to assign a value to dsSortOrder and dsSortColumn on the inital load?

    E.g.: dsSortOrder == '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.
  • Commented on 06-06-2008 at 9:34 AM
    Oddly the API only provides getMethods, not set. Let me ping the Spry guys.
  • Kin Blas #
    Commented on 06-09-2008 at 11:28 AM
    You want to use the sortOnLoad and sortOrderOnLoad data set constructor options:

    http://labs.adobe.com/technologies/spry/articles/d...

    --== Kin ==--
  • Commented on 11-02-2008 at 8:15 PM
    Anyone got any ideas how I can get the SpryJSONDataSet to load a JSON object (js variable) instead of from a url?
  • Commented on 11-03-2008 at 3:20 PM
    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?

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty