DataTable Initial Sort
I have a datatable which is receiving generated data from an array. When displaying the datatable, I would like to have it sorted by one column. I've looked around on the internet, but all tutorials show how to sort the datatable when a user clicks on a header. I don't need user inputed sorting functionality, but just to have the table be sorted by the smallest value of a column returning a double.
What's the best way to do this? Is there no attribute I can give to a column to have it sort by that?
Thanks
[533 byte] By [
mon.goosea] at [2007-11-27 11:34:00]

# 1
Just use that same code to sort the datatable directly after loading and leave the commandlinks away?
Or, even better, use the database sorting capabilities using an ORDER BY query.
# 2
Thanks for the help, I have included the DtoComparator.java and now am running this line to sort the array before passing it to the datatable:
Arrays.sort(dueArray, new DtoComparator("getDaysLeft", true));
I hope there's nothing wrong here, but it was simpler for me to just sort the array instead of the collection.
# 3
As BalusC suggested, use the database if possible. Your database implementor has put a lot of effort into being able to do these kinds of things efficiently, that's what databases are for.
# 4
Indeed. If you sort the data only once per request, then gently use the database to sort the data.
A comparator is useful if you already have the data in session and want to let the client to sort it afterwards. Querying the DB again and again by the client would be more expensive otherwise.
# 5
Thanks for the suggestions, and I had thought about using the database to query from the beginning. The trouble here is that the data used to create the datatable is generated from a few queries and not from a single query where I can apply such a restriction