Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nina 5 posts 25 karma points
    Dec 02, 2010 @ 16:21
    Nina
    0

    dropdownlist with sorting options

    hy everbody!

    i´m completely new to umbraco and xslt and i´ve started with it a few days ago, so i hope my problem is just a newbie question. also i have to say sorry for my poor english i hope you will understand what i mean ^^

    now my problem:
    i want to have a dropdownlist on my website with following options: price asc, price desc, categories alphabetical, eventDate asc and eventDate desc. when a user clicks on one of these options the content should get sorted for this option -> click on price asc should sort the whole content on this site price asc.

    what i have:
    in my document type "CWS_EventItem" i´ve created a new tab called "Sorts" with two items: alias:cat with type textstring, alias: price als with type textstring. ´ve created an xslt file called "sorter" which i integrated in the template called "CWS:EventNewsList" (or something like that). i have following code for the dropdownlist in this xsltfile

    <select name="sortierung">
     <option value="dateasc">Datum aufsteigend</option>
     <option value="datedesc">Datum absteigend</option>
     <option value="cat">Kategorie alphabetisch</option>
     <option value="priceasc">Preis aufsteigend</option>
     <option value="pricedesc">Preis absteigend</option>
    </select>

    this gives me the dropdownlist and i know that the following code sorts the content:

     <xsl:sort select="price" data-type="number" order="ascending"/>
     <xsl:sort select="cat" order="ascending"/>
     -<xsl:sort select="eventDate" order="descending"/>
    ...

    well: i know how to sort and i have a dropdownlist, but unfortunately i have really no idea how i can put this together so when the user clicks on price asc of the dropdownlist the content gets sorts for this criteria.

     

    does anybody had the same problem and could help me please, please. please? i´m getting really desperate :(

  • Søren Tidmand 129 posts 366 karma points
    Dec 02, 2010 @ 17:33
    Søren Tidmand
    0

     

    Hi Nina,

    You can solve this in a couple of different ways. I've got two suggestions.

    If you show the Event items in a table, I can recommend the jQuery plugin tablesorter

    But you're probably showing items in a list, and then I would make each option link to the same page with a query string describing which type and order of sorting the end-user is selecting, for example:

    www.yoursite.com/events.aspx?sort=eventDate&order=desc

    In the xslt you will have to ask for content in the query string and pass it on to the sorting method.

    <xsl:variable name="SortOrder">
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('order') = 'desc'">
    <xsl:value-of select="descending" />
    </xsl:when>
    <xsl:otherwise>
    <!-- the standard way of ordering -->
    <xsl:value-of select="ascending" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="SortBy">
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('sort') = 'cat'">
    <xsl:value-of select="cat" />
    </xsl:when>
    <xsl:when test="umbraco.library:RequestQueryString('sort') = 'price'">
    <xsl:value-of select="price" />
    </xsl:when>
    <xsl:otherwise>
    <!-- the standard way of sorting -->
    <xsl:value-of select="eventDate" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <!-- We need to set data-type to number or text depending on what sortby equals -->
    <xsl:variable name="DataType">
    <xsl:choose>
    <xsl:when test="$SortBy='price'">
    <xsl:value-of select="'number'" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="'text'" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <ul>
    <xsl:for-each select="YourData">
    <xsl:sort select="@*[name() = $SortBy]" order="{$SortOrder}" data-type="{$DataType}"/>
    <li>
    ....
    </li>
    </xsl:for-each>
    </ul>

    Parts of the code is taken from CWS ListNewsEvents and adjusted to your needs. I haven't actually run the xslt to see whether it works, but if not please get back to me.

    I hope this is what you're looking for.

    Cheers,

    Søren

  • Nina 5 posts 25 karma points
    Dec 03, 2010 @ 09:12
    Nina
    0

    hy and first: thank you for your prompt answer! it makes me happy to see that this forum seems to be an active forum and that i get help :) i think the tablesorter isn´t really what i´m looking for because i have another structure: i have 3 columns with news or eventitems and one of this items consists of:

    event/newsdate - category (health, lifestyle, finance ...)
    heading - price
    article content .....

    so your second option should meet my requirements, but (probably a stupid question but i´m really new to this stuff and don´t really know much until now. hope it´s getting better!) how and where can i build these querystrings? do i need an extra xslt file for this or do i have to change the url name of the site?

    thank you for your help! - nina

Please Sign in or register to post replies

Write your reply to:

Draft