SqlQuery integrated paging with custom navigation display.

This example shows how easy it is to integrate paging in an SqlQuery macro (using the PagingId parameter).

Using the PagingId parameter makes the SqlQuery macro convert the Sql given to a paging query, thus selecting only the data needed from the database source (paging at the source). You can see that by monitoring the database activity using a trace.
This is very different from storing a datatable in cache, then paging through the cached datatable, in terms of resources needed and performance.
You have to always make the design decision what the best way is in any given scenario.

Also, in this example, paging navigation links are displayed in a custom fashion, using this.location(). This provides maximum flexibility.

Smartsite SXML CopyCode image Copy Code
<se:hidden>
    <se:pagetranslations localid="helpers">
        <se:collection>
            <se:member name="link(nr, text)"><a href="{translation.arg(nr)}">{translation.arg(2)}</a></se:member>
        </se:collection>
    </se:pagetranslations>
    
    <se:paging pagesize="10" queryprefix="p1" />
    
    {buffer.set(cur, scope.paging.current())}
    {buffer.set(range, 6)}
    {buffer.set(start, math.max(scope.paging.current()-($range/2),1))}
    
</se:hidden>
<se:sqlquery pagingid="paging"
    sql="select nr, title, description from {channel.view()} where parent={cms.getitemnumber(MACROS)} order by title" 
    whitespace="remove">
    <se:parameters>
        <se:parameter name="format">
            <se:rowformat>
                {char.tab()}<li><a href="{this.location()}">{this.field(title)}</a>
                <div><span></span>{this.field(description)}</div></li>{char.crlf()}
            </se:rowformat>
        </se:parameter>
        <se:parameter name="resultformat">
            <ul>{char.crlf()}{this.result()}</ul>{char.crlf()}
        </se:parameter>
    </se:parameters>
</se:sqlquery>

<se:for from="{buffer.get(start)}" to="{math.min($start+$range, scope.paging.count())}" whitespace="remove">
    {buffer.set(n, this.index())}
    <div class="{string.concat(paging, sys.iif($n==$cur, ' currentpage'))}">
        <se:if expression="$cur!=$n" trim="both">
            <se:then>
                {translation.helpers.link(scope.paging.location($n), $n)} 
            </se:then>
            <se:else>
                {buffer.get(n)}
            </se:else>
        </se:if>
    </div>{char.crlf()}
</se:for>
Example Result CopyCode image Copy Code
<ul>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_AIMRendertemplateModule">AIM Macro</a><div><span></span>AIM Rendering macro</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_AIMScanModule">AIMScan Macro</a><div><span></span>AIM scanning macro. Scans itemdata for references</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_AspNetAppModule">Application Macro</a><div><span></span>Asp.Net application macro. Used to incorporate ASP.NET applications.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_BinaryDataModule">Binary Macro</a><div><span></span>Returns binary data from images or word documents.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_BufferModule">Buffer Macro</a><div><span></span>Macro used to store or retrieve buffers.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_CachedData">Cache Macro</a><div><span></span>Cache macro. Used to cache blocks of SXML.The cache key is auto-generated based on the SXML in the Xml (default) parameter.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_CacheFile">CacheFile Macro</a><div><span></span>Implements file based caching on the given page output.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_WebToolkit_CalendarModule">Calendar Macro</a><div><span></span>Smartsite Web Toolkit Calendar module.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_CmsSaveModule">CmsUpdate Macro</a><div><span></span>Saves items into to the CMS.</div></li>
    <li><a href="/test.net?id=Macro_T_Smartsite_Runtime_Modules_CodeModule">Code Macro</a><div><span></span>Represents source code that will be compiled and executed using the CodeDom. The first class deriving from Module.</div></li>
</ul>
 
 
<div class="paging currentpage">1</div>
<div class="paging"><a href="/test.net?id=29870&amp;p1_page=2&amp;p1_count=85">2</a></div>
<div class="paging"><a href="/test.net?id=29870&amp;p1_page=3&amp;p1_count=85">3</a></div>
<div class="paging"><a href="/test.net?id=29870&amp;p1_page=4&amp;p1_count=85">4</a></div>
<div class="paging"><a href="/test.net?id=29870&amp;p1_page=5&amp;p1_count=85">5</a></div>
<div class="paging"><a href="/test.net?id=29870&amp;p1_page=6&amp;p1_count=85">6</a></div>
<div class="paging"><a href="/test.net?id=29870&amp;p1_page=7&amp;p1_count=85">7</a></div>