Up: Chapter 14

14.2 Solution

The DB.runQuery(sql_query_string) method returns (List[String], List[List[String]]), to put that in a table, your view looks like:
<table class="lift:MySnippet">
  <thead>
    <tr><th id="my_th">Field Name</th></tr>
  </thead>
  <tbody>
  <tr id="my_tr"><td>An item</td></tr>
  </tbody>
</table>
And your snippet uses CSS Selector Transforms (See ) and looks like:
object MySnippet {
  def render = {
    val (fieldNames: List[String], fieldValues: List[List[String]]) = DB.runQuery(...)
‚Äč
    "#my_th *" #> fieldNames &
    "#my_tr *" #> fieldValues.map(values => "td *" #> values)
  }
}
Up: Chapter 14

(C) 2012 David Pollak