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

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


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 =; var y =; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); } ...

by Sachin
Tag: sorting

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