how to sort the csv items based on a particular field in freemarker?

74 Views Asked by At

Name,RollNo,Height,Weight Adam,10,160,52 Andrew,11,152,40 Brad,12,162,55 Bran,13,161,53

In this case i need to sort the rows based on the Height field. Can you please suggest your answers?

1

There are 1 best solutions below

0
ddekany On

I'm not sure how Smooks expose the CSV to the template. If it's a list of rows, where you can read cells in a row like row.Height (like <#list myCsv as row>${row.Height}</#list>), then myCsv?sort_by('Height') should work.

Note however that in general such things should be done outside the template. For more complex cases (even with sorting by multiple fields) you will run into limitations quickly.