Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Feb 23, 2011 @ 01:47
    syn-rg
    0

    Pagination needs to include selected State

    I'm working on a projects gallery which includes a number of drop down menus that filter the displayed projects.
    It works very well, displaying 12 projects per page.

    However if I filter my projects by "State" under the "All Locations" drop down and select "VIC" it appends the URL with "?state=VIC". But if I try to click onto page 2 of the VIC displayed projects I return no results even though there is a page there. The code for the pagination is removing the "?state=VIC" from the URL.

    So I've tried adding "?state=<xsl:value-of select="projectState" />" to my pagination code, but the selected states value is not being passed into it.

    Has anyone got any suggestions?
    Cheers, JV

    http://isis.brandtoolbox.com.au/projects/projects.aspx?state=VIC

    ProjectsAlbum.xslt (code that displays the project gallery)

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:emint="urn:my-scripts"
    exclude-result-prefixes="msxml umbraco.library">
    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:variable name="FF_projectList" select="umbraco.library:RequestForm('projects')" />
    <xsl:variable name="FF_projectTypeList" select="umbraco.library:RequestForm('projectType')" />
    <xsl:variable name="FF_projectLocationList_Temp" select="umbraco.library:RequestForm('projectLocation')" />
    <xsl:variable name="FF_sortType" select="umbraco.library:RequestForm('sortType')" />
    <xsl:variable name="FF_projectShowAll" select="umbraco.library:RequestForm('projectShowAll')" />
    <xsl:variable name="QS_projectLocationList" select="umbraco.library:RequestQueryString('state')" />

    <xsl:variable name="FF_projectLocationList">
    <xsl:choose>
    <xsl:when test="$QS_projectLocationList = ''"><xsl:value-of select='$FF_projectLocationList_Temp' /></xsl:when>
    <xsl:otherwise><xsl:value-of select='$QS_projectLocationList' /></xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:param name="currentPage"/>
    <xsl:template match="/">



    <xsl:variable name="sectionId">
    <xsl:if test="($FF_projectList = 0 or $FF_projectList = '')">
    <xsl:value-of select="$currentPage/@id" />
    </xsl:if>
    <xsl:if test="($FF_projectList &gt; 0)">
    <xsl:value-of select="$FF_projectList" />
    </xsl:if>
    </xsl:variable>

    <input type="hidden" id="projectShowAll" name="projectShowAll" />

    <xsl:variable name="possibleNodes" select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name() != 'ProjectGallery' and name() = 'ProjectPage']" />
    <xsl:variable name="matchedNodesIdList">
    <xsl:for-each select="$possibleNodes" >
    <xsl:call-template name="projectNode">
    <xsl:with-param name="project" select="."/>
    </xsl:call-template>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="matchedNodes" select="$possibleNodes[contains($matchedNodesIdList, concat(@id, ';'))]" />

    <xsl:variable name="itemsPerPage">12</xsl:variable>
    <xsl:variable name="recordsPerPage">
    <xsl:choose>
    <xsl:when test="$FF_projectShowAll = 'true'">
    <xsl:value-of select="count($matchedNodes)" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$itemsPerPage" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="pageNumber">
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="numberOfRecords" select="count($matchedNodes)"/>
    <xsl:value-of select="umbraco.library:RegisterStyleSheetFile('slider1', '/css/project_gallery.css')"/>
    <div id="project_gallery">
    <xsl:if test="$numberOfRecords = 0">
    <div id="projects_error_msg">
    <p>No projects with that search criteria were found.</p>
    </div>
    </xsl:if>
    <ul>
    <xsl:for-each select="$matchedNodes">
    <xsl:sort select="@nodeName[$FF_sortType = 'Client' or $FF_sortType='']" order="ascending" />
    <xsl:sort select="completionDate[$FF_sortType = 'NewestToOldest' or $FF_sortType='']" order="descending" />

    <xsl:sort select="./../@nodeName [$FF_sortType = 'Sector']" order="ascending" />
    <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
    <li>
    <div id="project">
    <!-- get first photo thumbnail -->
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="count(./* [@isDoc]) &gt; 0">
    <img src="{concat(substring-before(./*/projectImage,'.'), '_thumb_180.jpg')}"/>
    </xsl:if>
    <xsl:if test="completionDate != ''">
    <h1><xsl:value-of select="umbraco.library:FormatDateTime(completionDate, 'MMMM yyyy')"/></h1>
    </xsl:if>
    <xsl:if test="projectClient != ''">
    <h2>
    <!-- <xsl:value-of select="projectClient" /> -->
    <xsl:value-of select="umbraco.library:StripHtml(pageTitle)" />
    </h2>
    </xsl:if>
    <xsl:if test="projectLocation != '' and projectState != ''">
    <p><xsl:value-of select="projectLocation" />,&nbsp;<xsl:value-of select="projectState" /></p>
    </xsl:if>
    </a>
    </div>
    </li>
    </xsl:if>
    </xsl:for-each>
    </ul>

    <xsl:if test="$numberOfRecords &gt; $recordsPerPage or $FF_projectShowAll != ''">
    <div id="page_numbers_nav">
    <xsl:if test="$numberOfRecords &gt; $recordsPerPage">
    <!--<xsl:if test="$pageNumber &gt; 1">
    <li>
    <xsl:call-template name="pageUrl">
    <xsl:with-param name="pageNumber" select="$pageNumber - 1"/>
    <xsl:with-param name="pageText" select="'previous'"/>
    <xsl:with-param name="currentPageNumber" select="$pageNumber"/>
    <xsl:with-param name="class" select="'previous'"/>
    <xsl:with-param name="currentPageUrl">
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />?
    </xsl:with-param>
    </xsl:call-template>
    </li>
    </xsl:if>-->

    <xsl:if test="$numberOfRecords &gt; $recordsPerPage">
    <xsl:call-template name="for.loop">
    <xsl:with-param name="i">1</xsl:with-param>
    <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
    <xsl:with-param name="count" select="ceiling(count($matchedNodes) div $recordsPerPage)"></xsl:with-param>
    </xsl:call-template>
    </xsl:if>



    <!--<xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
    <li>
    <xsl:call-template name="pageUrl">
    <xsl:with-param name="pageNumber" select="$pageNumber + 1"/>
    <xsl:with-param name="pageText" select="'next'"/>
    <xsl:with-param name="currentPageNumber" select="$pageNumber"/>
    <xsl:with-param name="class" select="'next'"/>
    <xsl:with-param name="currentPageUrl">
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />?
    </xsl:with-param>
    </xsl:call-template>
    </li>
    </xsl:if>-->
    </xsl:if>
    <xsl:variable name="currentUrl" select="umbraco.library:NiceUrl($currentPage/@id)" />

    <!-- Satjinder - Code for "SHOW ALL" function -->

    <xsl:choose>
    <xsl:when test="$FF_projectShowAll = ''" >
    <xsl:if test="$numberOfRecords &gt; $recordsPerPage">
    <li class="show_all" id="showAll_Buttons">
    <a>
    <xsl:attribute name="href">
    javascript:Projects_SetShowAll(true, '<xsl:value-of select="$currentUrl" />');
    </xsl:attribute>
    Show all&nbsp;&nbsp;<span><xsl:value-of select="$numberOfRecords"/></span>
    </a>
    </li>
    </xsl:if>
    </xsl:when>
    <xsl:otherwise>
    <li>
    <a class="show_paged">
    <xsl:attribute name="href">
    javascript:Projects_SetShowAll(false, '<xsl:value-of select="$currentUrl" />');
    </xsl:attribute>
    Show paged
    </a>
    </li>
    </xsl:otherwise>
    </xsl:choose>

    <!-- Close -->
    </div>
    </xsl:if>
    </div>

    <script type="text/javascript">

    function GotoNextPage(url)
    {
    //$("#searchImageClicked").val('search');
    document.forms[0].action=url;
    document.forms[0].submit();
    }

    function Projects_SetShowAll(flag, url){
    if (flag){
    $("#projectShowAll").val('true');
    }
    else{
    $("#projectShowAll").val('');
    }
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit();
    }

    </script>
    </xsl:template>

    <xsl:template name="for.loop">
    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i &lt;= $count">
    <li><xsl:if test="$page != $i">
    <xsl:call-template name="pageUrl">
    <xsl:with-param name="pageNumber" select="$i"/>
    <xsl:with-param name="pageText" select="$i"/>
    <xsl:with-param name="currentPageNumber" select="$page"/>
    <xsl:with-param name="class" select="'next_page'"/>
    <xsl:with-param name="currentPageUrl">
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />?state=<xsl:value-of select="projectState" />
    </xsl:with-param>
    </xsl:call-template>
    </xsl:if></li>
    <xsl:if test="$page = $i">
    <span class="currentpage">
    <xsl:value-of select="$i" />
    </span>
    </xsl:if>
    </xsl:if>
    <xsl:if test="$i &lt;= $count">
    <xsl:call-template name="for.loop">
    <xsl:with-param name="i">
    <xsl:value-of select="$i + 1"/>
    </xsl:with-param>
    <xsl:with-param name="count">
    <xsl:value-of select="$count"/>
    </xsl:with-param>
    <xsl:with-param name="page">
    <xsl:value-of select="$page"/>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:if>
    </xsl:template>

    <xsl:template name="projectNode">
    <xsl:param name="project"/>
    <xsl:variable name="projectLocationList"></xsl:variable>
    <xsl:if test="$projectLocationList = $FF_projectLocationList">dd</xsl:if>
    <xsl:if test="((emint:SearchTerminValue2($project/projectType, $FF_projectTypeList) = 'true') and (emint:CompareIfValueIsThere1($project/projectState, $FF_projectLocationList, '/projects/projects.aspx') = 'true'))">
    <xsl:value-of select="$project/@id" />;
    </xsl:if>
    </xsl:template>

    <xsl:template name="pageUrl">
    <xsl:param name="pageNumber" select="1"/>
    <xsl:param name="pageText" select="1"/>
    <xsl:param name="class" select="page" />
    <xsl:param name="currentPageNumber" select="1"/>
    <xsl:param name="currentPageUrl" select="''"/>
    <a>
    <xsl:attribute name="class">
    <xsl:value-of select="$class" />
    </xsl:attribute>
    <xsl:attribute name="href">
    javascript:GotoNextPage('<xsl:value-of select="$currentPageUrl"/>&amp;tid=<xsl:value-of select="$pageNumber"/>&amp;page=<xsl:value-of select="$pageNumber"/>');
    </xsl:attribute>
    <xsl:value-of select="$pageText"/>
    </a>
    </xsl:template>



    <msxsl:script language="C#" implements-prefix="emint">
    <![CDATA[


    public bool CompareIfValueIsThere(string term, string value)
    {
    if (string.IsNullOrEmpty(value))
    {
    return true;
    }
    if (value.ToUpper() == term.ToUpper())
    {
    return true;
    }
    return false;
    }

    public bool CompareIfValueIsThere1(string term, string value, string emptyValue)
    {
    if (string.IsNullOrEmpty(value))
    {
    return true;
    }
    if (value == emptyValue)
    {
    return true;
    }
    if (value.ToUpper() == term.ToUpper())
    {
    return true;
    }
    return false;
    }
    public bool SearchTerminValue(string value, string term)
    {
    string[] terms = term.Split('/');
    foreach (string item in terms)
    {
    bool found = SearchTerminValue1(value, item);
    if (!found)
    {
    return false;
    }
    }
    return true;
    }

    public bool SearchTerminValue1(string value, string term)
    {
    string[] terms = term.Split(' ');
    foreach (string item in terms)
    {
    int ind = value.IndexOf(item, StringComparison.InvariantCultureIgnoreCase);
    if (ind >= 0)
    {
    return true;
    }
    }
    return false;
    }


    public bool SearchTerminValue2(string value, string term)
    {
    string[] terms = term.Split(',');
    foreach (string item in terms)
    {
    int ind = value.IndexOf(item, StringComparison.InvariantCultureIgnoreCase);
    if (ind >= 0)
    {
    return true;
    }
    }
    return false;
    }


    ]]>
    </msxsl:script>
    </xsl:stylesheet>

    ProjectsFilter.xslt (code that filters the project gallery)

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:variable name="FF_projectList" select="umbraco.library:RequestForm('projects')" />
    <xsl:variable name="FF_projectTypeList" select="umbraco.library:RequestForm('projectType')" />
    <xsl:variable name="FF_projectLocationList_Temp" select="umbraco.library:RequestForm('projectLocation')" />
    <xsl:variable name="FF_sortType" select="umbraco.library:RequestForm('sortType')" />

    <xsl:variable name="QS_projectLocationList" select="umbraco.library:RequestQueryString('state')" />

    <xsl:variable name="FF_projectLocationList">
    <xsl:choose>
    <xsl:when test="$QS_projectLocationList = ''"><xsl:value-of select='$FF_projectLocationList_Temp' /></xsl:when>
    <xsl:otherwise><xsl:value-of select='$QS_projectLocationList' /></xsl:otherwise>
    </xsl:choose>
    </xsl:variable>


    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <!-- start writing XSLT -->

    <form action="#">
    <div id="project_gallery_filter">
    <fieldset>
    <select name="projects" id="projects" >
    <option value="{umbraco.library:NiceUrl($currentPage/@id)}">All sectors</option>
    <xsl:for-each select="$currentPage/* [@isDoc]">
    <option value="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$FF_projectList = ./@id">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </option>
    </xsl:for-each>
    </select>
    </fieldset>
    <fieldset>
    <xsl:variable name="projectTypeList" select="umbraco.library:GetPreValues(1212)//preValue" />
    <select name="projectType" id="projectType" onchange="document.getElementById('aspnetForm').submit()" >
    <option value="">All project types</option>
    <xsl:for-each select="$projectTypeList">
    <xsl:sort order="ascending" data-type="text" />
    <option value="{.}">
    <xsl:if test="$FF_projectTypeList = .">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="." />
    </option>
    </xsl:for-each>
    </select>
    </fieldset>

    <fieldset>
    <xsl:variable name="projectLocationList" select="umbraco.library:GetPreValues(1211)//preValue" />
    <select name="projectLocation" id="projectLocation" >
    <option value="{umbraco.library:NiceUrl($currentPage/@id)}">All locations</option>
    <xsl:for-each select="$projectLocationList">
    <xsl:sort order="ascending" data-type="text" />
    <option value="{umbraco.library:NiceUrl($currentPage/@id)}?state={.}">
    <xsl:if test="$FF_projectLocationList = .">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="." />
    </option>
    </xsl:for-each>
    </select>
    </fieldset>

    <fieldset>
    <select name="sortType" id="sortType" onchange = "document.getElementById('aspnetForm').submit()" >
    <option value="">Sort by</option>
    <option value="NewestToOldest">
    <xsl:if test="$FF_sortType= 'NewestToOldest'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    Newest To Oldest
    </option>
    <option value="Client">
    <xsl:if test="$FF_sortType= 'Client'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    Client A-Z</option>
    <option value="Sector">
    <xsl:if test="$FF_sortType= 'Sector'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    Sector</option>
    </select>
    </fieldset>
    </div>
    </form>

    <script type='text/javascript'>
    $(document).ready(function(){
    $("#projects").change(function(){
    $("#aspnetForm").attr("action",$(this).val());
    $("#aspnetForm").submit();
    });
    $("#projectLocation").change(function(){
    $("#aspnetForm").attr("action",$(this).val());
    $("#aspnetForm").submit();
    });


    });
    </script>


    </xsl:template>

    </xsl:stylesheet>
  • Rob Watkins 369 posts 701 karma points
    Feb 23, 2011 @ 15:21
    Rob Watkins
    1

    In your for.loop template, (which I'm presuming is where the page numbers are being generated?), you are using projectState but I can't see why the current node when you enter the for loop would be a project, unless I'm missing something?

    Don't you want to grab the state out of the querystring if present for the pagination control?

     

  • syn-rg 282 posts 425 karma points
    Feb 23, 2011 @ 23:21
    syn-rg
    0

    Hi Rob,

    The reason it is using currentPageUrl is to keep the URL the same but append the page number to the end of the URL. Without it the currentPageUrl code, the resulting URL becomes: http://isis.brandtoolbox.com.au/projects/state=&tid=4&page=4. Which isn't a page.

    Can you suggest another alternative?

    Yes I want to grab the state out of the querystring if it is present.

  • syn-rg 282 posts 425 karma points
    Feb 23, 2011 @ 23:33
    syn-rg
    0

    Solved it!

    Thanks to Rob, I looked at my code again. Should have been using the following code:

    ?state=<xsl:value-of select='$QS_projectLocationList' />

    Instead of the the code I was using:

    ?state=<xsl:value-of select="projectState" />
  • Rob Watkins 369 posts 701 karma points
    Feb 24, 2011 @ 10:42
    Rob Watkins
    0

    Coolio, glad you solved it!

Please Sign in or register to post replies

Write your reply to:

Draft