Dynamic sortBy

607 views
Skip to first unread message

Pradeep Kumar Mishra

unread,
Nov 14, 2012, 4:09:30 AM11/14/12
to scala...@googlegroups.com
This is with reference to thread - https://groups.google.com/forum/#!searchin/scalaquery/sort/scalaquery/8K1dLmoIh0A/brwESE1eDlIJ

What's the current best way to go for dynamic sorting. I am using following query

val q2 = q1.sortBy[scala.slick.lifted.Column[Option[String]]](queryParams.sortTerm match {
      case "itemSKU" =>   _._2
      case "price" =>  _._3
      case _ =>   _._1
    })

But since I need to specify type (in red) the returning column type can not be dynamic. Looks like I am doing something wrong here.

Pradeep Kumar Mishra

unread,
Nov 14, 2012, 4:13:12 AM11/14/12
to scala...@googlegroups.com
FYI getting following error if I do not specify any type in sortBy

No implicit view available from scala.slick.lifted.Column[_ >: Option[String] with Double with String] => scala.slick.lifted.Ordered.

Ryan Bair

unread,
Nov 14, 2012, 9:05:50 AM11/14/12
to scala...@googlegroups.com
Columns have methods desc and asc on them which return an Ordering. Rather than just returning _._2 from the case you could return _._2.desc instead. You should not need the type parameter if you do that.




--
 
 
 

Pradeep Kumar Mishra

unread,
Nov 14, 2012, 7:33:25 PM11/14/12
to scala...@googlegroups.com
Thank you so much Ryan. it worked perfectly.
Reply all
Reply to author
Forward
0 new messages