[Lift] Re: Pagination in lift?
On Sun, Jun 28, 2009 at 1:06 PM, Timothy Perrett timo...@getintheloop.euwrote: You don't mention if your using JPA or Mapper - if your using mapper then the answer is no we don't have any built in support but its not to difficult to display limited lists. You could grab all the results then do some manipulation on the list in memory if you only have a small dataset, alternatively you could craft your own queries using limiting / offsetting. Tim, Selecting a subset of stuff with Mapper is pretty simple: Users.findAll(OrderBy(User.id, Ascending), StartAt(50), MaxRows(10)) Alternatively, if your using JPA, you can use the stuff built into jpa; more info here: http://is.gd/1hfCg Cheers, Tim On Jun 28, 8:44 pm, Naftoli Gugenhem naftoli...@gmail.com wrote: Does lift have built in support for pagination -- breaking up a query and continuing it across multiple pages, and clicking the headers to sort? If not how hard is it? -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Pagination in lift?
Tim, Selecting a subset of stuff with Mapper is pretty simple: Users.findAll(OrderBy(User.id, Ascending), StartAt(50), MaxRows(10)) Oh wow, really didnt know that was possible... i'll shut my jpa-using mouth in future ;-) hehe. Cheers, Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Pagination in lift?
You don't mention if your using JPA or Mapper - if your using mapper then the answer is no we don't have any built in support but its not to difficult to display limited lists. You could grab all the results then do some manipulation on the list in memory if you only have a small dataset, alternatively you could craft your own queries using limiting / offsetting. Alternatively, if your using JPA, you can use the stuff built into jpa; more info here: http://is.gd/1hfCg Cheers, Tim On Jun 28, 8:44 pm, Naftoli Gugenhem naftoli...@gmail.com wrote: Does lift have built in support for pagination -- breaking up a query and continuing it across multiple pages, and clicking the headers to sort? If not how hard is it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Pagination in lift?
Thanks. (I was asking about the view end more than the model side, but I'm using Mapper.) So can you specify limits and offset without resorting to native queries? If so, how? And if not, what would it take to write cross-database lift support? - Timothy Perretttimo...@getintheloop.eu wrote: You don't mention if your using JPA or Mapper - if your using mapper then the answer is no we don't have any built in support but its not to difficult to display limited lists. You could grab all the results then do some manipulation on the list in memory if you only have a small dataset, alternatively you could craft your own queries using limiting / offsetting. Alternatively, if your using JPA, you can use the stuff built into jpa; more info here: http://is.gd/1hfCg Cheers, Tim On Jun 28, 8:44 pm, Naftoli Gugenhem naftoli...@gmail.com wrote: Does lift have built in support for pagination -- breaking up a query and continuing it across multiple pages, and clicking the headers to sort? If not how hard is it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Pagination in lift?
See the Lift book (http://tinyurl.com/mta3h5), section 6.1.10 6.1.8 which discusses pagination with Mapper... Marc On 29/06/2009, at 5:44 AM, Naftoli Gugenhem wrote: Does lift have built in support for pagination -- breaking up a query and continuing it across multiple pages, and clicking the headers to sort? If not how hard is it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Pagination in lift?
If you're using JPA, pagination is pretty trivial. Here's what I use in my app to provide it; the links stuff is primitive and needs improvement but works. import net.liftweb.util.Helpers._ import net.liftweb.http.SHtml._ import scala.xml._ class Paginator[A](val queryBase : String, val ordering : Option[String], val params : Pair[String,Any]*) extends Paging[A] { def count() : Long = { val query = EM.createQuery[Long](SELECT COUNT (o) + queryBase) for (p - params) query.setParameter(p._1, p._2) query.getSingleResult } /** 0 based page index. */ def getPage(page : Int, pageSize : Int) : Collection[A] = { val query = EM.createQuery[A](SELECT o + queryBase + ordering.getOrElse()) for (p - params) query.setParameter(p._1, p._2) query.setFirstResult(page * pageSize) query.setMaxResults(pageSize) query.getResultList } /** * Display a pagination list for the order search. */ def pageLinks(maxRecords: Int, pageSetter: Int = Unit, loc: String, xhtml : NodeSeq) : NodeSeq = { val pageCount = (count / maxRecords).intValue + 1 (0 until pageCount).flatMap(i = bind(page, xhtml, link - link(loc, () = pageSetter(i), Text(i.toString } } object Paginator { def emptyPaginator[A] = new Paging[A]() { def count = 0 def getPage(page : Int, pageSize: Int) : Collection[A] = Nil } } On Sun, Jun 28, 2009 at 1:44 PM, Naftoli Gugenhemnaftoli...@gmail.com wrote: Does lift have built in support for pagination -- breaking up a query and continuing it across multiple pages, and clicking the headers to sort? If not how hard is it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---