[Lift] Re: Alternating row colors

2009-05-11 Thread marius d.

Assume that in your snippet you have a List[String] that you want to
render as table rows such as:


val list = one :: two :: three :: Nil

def render(xhtml: NodeSeq): NodeSeq = {
 table{
  list.zipWithIndex((e, idx) = trtd{e}/td/tr %
 if (idx % 2 == 0)
 Null // Null is a MetaData here
 else
 (class - my_gray_out)
  )
  }/table
}

note that i did not test the code ... so it may not compile ... but I
hope you got the idea.

Br's,
marius

On May 11, 3:52 pm, Magnus Alvestad magnus.alves...@gmail.com wrote:
 I'm still learning lift (and scala). For my sample application I want
 to display a table with alternating row colors. I want to put the
 style in my CSS file and add a classname to every TR in my table to
 indicate odd and even rows. However, I don't know how to take a value
 from the snippet binding and assigning it to an attribute in my
 template file. Can anyone point me in the right direction?

 -Magnus
--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread Viktor Klang
This is the jQuery approach: (written from head, so may not compile)

CSS= .striped tr { background-color : #FF }
MARKUP= tabletbody
class=stripedtrtdhoho/td/trtrtdhaha/td/trtrtdhihi/td/tr/tbody/table
JS= $('.striped tr:nth-child(odd)').css('background-color','#DD');

Ref: http://dev.opera.com/articles/view/zebra-striping-tables-with-css3/

Cheers,
Viktor

On Mon, May 11, 2009 at 3:54 PM, marius d. marius.dan...@gmail.com wrote:


 Assume that in your snippet you have a List[String] that you want to
 render as table rows such as:


 val list = one :: two :: three :: Nil

 def render(xhtml: NodeSeq): NodeSeq = {
  table{
  list.zipWithIndex((e, idx) = trtd{e}/td/tr %
 if (idx % 2 == 0)
 Null // Null is a MetaData here
 else
 (class - my_gray_out)
  )
  }/table
 }

 note that i did not test the code ... so it may not compile ... but I
 hope you got the idea.

 Br's,
 marius

 On May 11, 3:52 pm, Magnus Alvestad magnus.alves...@gmail.com wrote:
  I'm still learning lift (and scala). For my sample application I want
  to display a table with alternating row colors. I want to put the
  style in my CSS file and add a classname to every TR in my table to
  indicate odd and even rows. However, I don't know how to take a value
  from the snippet binding and assigning it to an attribute in my
  template file. Can anyone point me in the right direction?
 
  -Magnus
 



-- 
Viktor Klang
Senior Systems Analyst

--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread Alex Boisvert
Here's another approach that I used in a small project recently...

I wrote a small stateful utility class,

class OddOrEven {
  private var isEven = true
  def getAndToggle: String = {
val s = toString
isEven = (!isEven)
s
  }
  override def toString = if (isEven) even else odd
}

and I use it as such,

val oddOrEven = new OddOrEven
for (row - rows) yield {
  tr class={oddOrEven.getAndToggle}
td ... /td
  /tr
}

But I generally prefer to put that presentation stuff in the CSS/Javascript
directly instead of in the code.

alex

On Mon, May 11, 2009 at 6:54 AM, marius d. marius.dan...@gmail.com wrote:


 Assume that in your snippet you have a List[String] that you want to
 render as table rows such as:


 val list = one :: two :: three :: Nil

 def render(xhtml: NodeSeq): NodeSeq = {
  table{
  list.zipWithIndex((e, idx) = trtd{e}/td/tr %
 if (idx % 2 == 0)
 Null // Null is a MetaData here
 else
 (class - my_gray_out)
  )
  }/table
 }

 note that i did not test the code ... so it may not compile ... but I
 hope you got the idea.

 Br's,
 marius

 On May 11, 3:52 pm, Magnus Alvestad magnus.alves...@gmail.com wrote:
  I'm still learning lift (and scala). For my sample application I want
  to display a table with alternating row colors. I want to put the
  style in my CSS file and add a classname to every TR in my table to
  indicate odd and even rows. However, I don't know how to take a value
  from the snippet binding and assigning it to an attribute in my
  template file. Can anyone point me in the right direction?
 
  -Magnus
 


--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread marius d.

Really neat, Viktor !

On May 11, 5:07 pm, Viktor Klang viktor.kl...@gmail.com wrote:
 This is the jQuery approach: (written from head, so may not compile)

 CSS= .striped tr { background-color : #FF }
 MARKUP= tabletbody
 class=stripedtrtdhoho/td/trtrtdhaha/td/trtrtdhihi/td/tr/tbody/table
 JS= $('.striped tr:nth-child(odd)').css('background-color','#DD');

 Ref:http://dev.opera.com/articles/view/zebra-striping-tables-with-css3/

 Cheers,
 Viktor



 On Mon, May 11, 2009 at 3:54 PM, marius d. marius.dan...@gmail.com wrote:

  Assume that in your snippet you have a List[String] that you want to
  render as table rows such as:

  val list = one :: two :: three :: Nil

  def render(xhtml: NodeSeq): NodeSeq = {
   table{
   list.zipWithIndex((e, idx) = trtd{e}/td/tr %
      if (idx % 2 == 0)
          Null // Null is a MetaData here
      else
          (class - my_gray_out)
   )
   }/table
  }

  note that i did not test the code ... so it may not compile ... but I
  hope you got the idea.

  Br's,
  marius

  On May 11, 3:52 pm, Magnus Alvestad magnus.alves...@gmail.com wrote:
   I'm still learning lift (and scala). For my sample application I want
   to display a table with alternating row colors. I want to put the
   style in my CSS file and add a classname to every TR in my table to
   indicate odd and even rows. However, I don't know how to take a value
   from the snippet binding and assigning it to an attribute in my
   template file. Can anyone point me in the right direction?

   -Magnus

 --
 Viktor Klang
 Senior Systems Analyst
--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread Magnus Alvestad

Thank you for your answers. I'll try to include some more detail
because I was not able to apply your suggestions to my code.

My template has a section like this:

lift:T.list
  table
question.list
  trtdquestion:text//td/tr
/question.list
  /table
/lift:T.list

while my snippet looks more or less like this:

class T {

  val questions = One :: Two :: Three :: Nil

  private def doList()(html:NodeSeq): NodeSeq = {
questions.flatMap(q = bind (question, html,
  text - Text(q))
  }

  def list(html:NodeSeq) = {
bind(question, html, list - doList() )
  }
}

-Magnus

--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread Timothy Perrett


Always there with a nice solution Viktor! Kudos!

On 11/05/2009 15:07, Viktor Klang viktor.kl...@gmail.com wrote:

 This is the jQuery approach: (written from head, so may not compile)
 
 CSS= .striped tr { background-color : #FF }
 MARKUP= tabletbody
 class=stripedtrtdhoho/td/trtrtdhaha/td/trtrtdhihi/td
 /tr/tbody/table
 JS= $('.striped tr:nth-child(odd)').css('background-color','#DD');
 
 Ref: http://dev.opera.com/articles/view/zebra-striping-tables-with-css3/
 
 Cheers,
 Viktor



--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread Magnus Alvestad

Ah! Based on Viktors suggestions and some more info at:

http://15daysofjquery.com/examples/zebra/

I was able to write this in a couple of lines of JQuery!

-Magnus

--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread Magnus Alvestad

To elaborate, I added a $(document).ready function to handle this.

However!

Some other pages have ajax functionality. When they update html in the
page, this html (and the page) will not be 'reprocessed' by JQuery.
Can I handle this in a generic manner?

-Magnus

On May 11, 5:09 pm, Magnus Alvestad magnus.alves...@gmail.com wrote:
 Ah! Based on Viktors suggestions and some more info at:

 http://15daysofjquery.com/examples/zebra/

 I was able to write this in a couple of lines of JQuery!

 -Magnus

--~--~-~--~~~---~--~~
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: Alternating row colors

2009-05-11 Thread David Pollak
On Mon, May 11, 2009 at 8:19 AM, Magnus Alvestad
magnus.alves...@gmail.comwrote:


 To elaborate, I added a $(document).ready function to handle this.

 However!

 Some other pages have ajax functionality. When they update html in the
 page, this html (and the page) will not be 'reprocessed' by JQuery.
 Can I handle this in a generic manner?


Sure... when you update with Ajax, you're always sending JavaScript, e.g.,
SetHtml(id, bnew stuff/b)... so you could do something like:

SetHtml(id, bnew stuff/b)  Raw( $('.striped
tr:nth-child(odd)').css('background-color','#DD');)





 -Magnus

 On May 11, 5:09 pm, Magnus Alvestad magnus.alves...@gmail.com wrote:
  Ah! Based on Viktors suggestions and some more info at:
 
  http://15daysofjquery.com/examples/zebra/
 
  I was able to write this in a couple of lines of JQuery!
 
  -Magnus

 



-- 
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
-~--~~~~--~~--~--~---