public
Description: The Lift web framework for Scala
Home | Edit | New

Example: Paginating Mapper-based snippets with sortable headers


import net.liftweb.mapper.view.Paginator
class Requests extends ModelSnippet[Request] {

  // Parameters: the MetaMapper, default sort field, and (headerName, field) tuples
  val paginator = new Paginator(Request, this, Request.id,
                                "id" -> Request.id,
                                "nature" -> Request.nature,
                                "client" -> Request.client,
                                "dispatcher" -> Request.dispatcher,
                                "priority" -> Request.priority,
                                "comment" -> Request.comment
  )
  

  def list(xhtml: NodeSeq) = 
    bind("prefix", paginator.paginate(xhtml),  ... )
}

View

nav: prefix is for navigation links. allpages is the list of page numbers, linked. The ’ | ’ is used as the separator in this example; you can choose something else if you like.
In the table header use the sort prefix sortable headers. For example .. gets linked with a link that sorts by id. When clicked a second time it sorts in descending.


<lift:surround with="default" at="content">
  <lift:Requests.list>
    <nav:records/>
    <br/>
    <nav:first/>
    <nav:prev/>  <nav:allpages> | </nav:allpages>  <nav:next/>
    <nav:last/>
    <table rules="groups" frame="hsides">
      <thead>
        <th><sort:id>
          <lift:loc>Req#</lift:loc>
        </sort:id>
        </th>
        <th><sort:nature>
          <lift:loc>Nature</lift:loc>
        </sort:nature></th>
        <th><sort:client>
          <lift:loc>Client</lift:loc>
        </sort:client></th>
        <th><sort:dispatcher>
          <lift:loc>Dispatcher</lift:loc>
        </sort:dispatcher></th>
        <th><sort:priority>
          <lift:loc>Priority</lift:loc>
        </sort:priority></th>
        <th><sort:comment>
          <lift:loc>Comments</lift:loc>
        </sort:comment></th>
        <th><lift:loc>Assigned volunteers</lift:loc></th>
      </thead>
       .....
    </table>
  </lift:Requests.list>
</lift:surround>
Last edited by nafg, Tue Oct 06 19:37:20 -0700 2009
Home | Edit | New
Versions: