Simple Paging Example

In this example, we navigate through a resultset created sing a simple search form.

Smartsite SXML CopyCode image Copy Code
<!-- //
    show a search form
-->
<form class="CoolForm" action="{request.location()}" method="get">
    <label for="q">Find</label> 
    <input class="Required Border Control TextBox" id="q" name="q" value="{request.query(q)}"/> 
    <br/>
    <input class="Control" type="submit" value="Search"/> 
</form>

{buffer.set(q, string.trim(request.query(q)), rem="Store our search buffer")}

<se:if expression="$q!=''">
    <se:paging id="srs" 
        pagesize="5"
        rem="Create a state machine for our paged search results"
    />

    
    <se:sqlquery 
        pagingid="srs"
        rem="SqlQuery macro bound to paging macro 'srs'"
        save="data"
        resulttype="datatable" 
        sql="select c.nr, c.title,c.description, c.moddate, u.fullname
            from {channel.view()} c 
            join vwUsers u on c.userid=u.nr
            where title like ? order by moddate desc"
        params="{string.concat('%', string.replace($q, '*','%'), '%')}"
    />

    <se:format inputdata="data" rem="Format the subset of the results">
        <se:rowformat>
            <li>
                <a href="{this.location()}">{this.name()}</a><br />
                <small>
                    {sys.iif(this.field(description)!='', string.concat(this.field(description), html.break()), '')}
                    {datetime.format(this.field(moddate), 'd MMM yyyy, HH:mm')} by {this.field(fullname, default='unknown author')}
                </small>
            </li>
        </se:rowformat>
        <se:resultformat>
            <h3>Results for '{buffer.get(q)}'</h3>
         
            <ul>
                {this.result()}
            </ul>
        </se:resultformat>
    </se:format>

    <!--//
        Show the paging navigation
    -->
    <span class="navbar {sys.iif(page.srs.count() == 1, 'hidden')}">
        {page.srs.goto(First)} 
        {page.srs.goto(Previous)}
        {page.srs.goto(Next)}
        {page.srs.goto(Last)}
        page {page.srs.current()} of {page.srs.count()}: 
        {page.srs.offset()} to {math.min(page.srs.totalcount(), page.srs.offset()+page.srs.size()-1)} of {page.srs.totalcount()} items.
    </span>

</se:if>