This is my solution
In controller:
params.max = 30
if(params.long('page')) {
params.offset = (params.long('page') - 1) * params.max
}
In tag lib:
static namespace = "my"
private final static Pattern OFFSET_PATTERN = Pattern.compile("offset=(\\d+)");
def paginate = { attrs, body ->
String str = g.paginate(attrs) // using grails gsp paginate tag
// make sure we delete max param with & (before or after)
str = str.replaceAll(/&max=\d+/, '').replaceAll(/max=\d+&/, '')
while (true) {
Matcher matcher = OFFSET_PATTERN.matcher(str)
if (matcher.find()) {
long pageNum = (matcher.group(1) as long)/params.long('max') + 1
// replace offset=0 with page=1, offset=30 with page=2, etc
str = matcher.replaceFirst('page=' + pageNum)
} else {
break;
}
}
out << str
}
So we can use my.paginate in our gsp views the same way we use standard grails gsp paginate tag. Looking forward your feedbacks and improvements