Ah, perfect! Thx!
Incidentally, I simplified in two places by instead of doing this:
List.range(0, rowNum).foldLeft(Util.emptyNodeSeq)((ns, i) => {
})
doing this:
List.range(0, rowNum).flatMap(i => {
})
(simlar change in the row function)
-harryh
On Aug 18, 3:52 pm, Ryan Donahue <[email protected]> wrote:
> You could do something like this.
>
> Snippet:
>
> def func(xhtml: NodeSeq): NodeSeq = {
> val foos = Foo.findAll(...)
> val rowSize = (S.attr("rowSize") openOr "10").toInt
> val rowNum = (foos.size + rowSize - 1) / rowSize
> List.range(0, rowNum).foldLeft(Util.emptyNodeSeq)((ns, i) => {
> val start = i*rowSize
> val end = start+rowSize
> ns ++ bind("list", xhtml, "row" -> row(foos.slice(start, end))
> _)
> })
> }
>
> private def row(foos:List[String])(xhtml: NodeSeq) : NodeSeq =
> foos.foldLeft(Util.emptyNodeSeq)((ns, foo) => ns ++ bind("foo",
> xhtml, "name" -> foo.name))
>
> Then your template can use table/tr/td or it could just use floating
> divs that wrap over when necessary:
>
> <table>
> <lift:MyPage.func rowSize="10">
> <tr>
> <list:row>
> <td><foo:name/></td>
> </list:row>
> </tr>
> </lift:MyPage.func>
> </table>
>
> OR
>
> <lift:MyPage.func>
> <list:row>
> <div class="cell"><foo:name/></div>
> </list:row>
> </lift:MyPage.func>
>
> For an empty NodeSeq that works in the foldLeft I've had to create the
> following. Anybody know a better way?
> object Util {
> val emptyNodeSeq : NodeSeq = NodeSeq.fromSeq(Seq(<xml:group></
> xml:group>))
>
> }
>
> On Aug 18, 2:58 pm, harryh <[email protected]> wrote:
>
> > I have a List[Foo] and I want to construct a table with 10 columns and
> > however many rows necessary to contain all the Foos. I feel like I
> > should do something like so, but it's not quite right yet:
>
> > <table>
> > <lift:MyPage.func>
> > <td><foo:name/></td>
> > </lift:MyPage.func>
> > </table>
>
> > def func(xhtml: NodeSeq): NodeSeq = {
> > val cells: List[NodeSeq] = Foo.findAll(...).flatMap(foo => {
> > bind("foo", xhtml, "name" -> foo.name)
> > })
>
> > // then reduce the list of cells putting in <tr>s in appropriate
> > places, but not sure how.
>
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---