Grails

Groovier way of sorting over multiple fields in a list of maps in groovy

Recently I was working on a Groovy and Grails Development project and had a requirement to sort multiple fields in a list of maps. I needed to sort the below list of maps by firstName, then by lastName and then by ascending age. It means first, the firstNames will be compared. If they are same, lastNames will be compared and even if...

by raj
Tag: sorting
10-Aug-2012

Database, Grails

Alphanumeric Sorting using Criteria Query (with MySQL database)

I am working on a Grails application with MySQL database. I had a use case in which I had to implement alphanumeric sorting using Criteria Query on Grails. By alphanumeric sorting I mean if there is a class Employee with field empId then on doing : [plain] Employee e1 = new Employee(empId:'emp10').save() Employee e2 = new...

by Gaurav Sharma
Tag: sorting
02-Feb-2012

Javascript/Ajax/JQuery

Sorting in javascript

Recently in my project I needed to sort an object list on the basis of object name. For the same purpose I created the following function [java] function sortList(objList) { objList.sort(sortByName); } function sortByName(a, b) { var x = a.name; var y = b.name; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); } ...

by Sachin
Tag: sorting
13-Mar-2011

Database, Grails

Groovy: Sort list of objects on the basis of more than one field

Usually, when we deal with databases, we don't face such kind of situation because we query database to get result-set in required order. But let's say you have a List of objects that you want to sort on the basis of two fields. Let's discuss it with an example. I have a list of Tasks (with date and priority fields). I want to sort...

by Salil
Tag: sorting
25-Jan-2011