Hi,
How do I sort data IN Ascending or Descending order. Following is a sample code. I want to sort on Amount i.e. float OR Value i.e. integer OR Name i.e. String. I am showing data in my app in table and want to provide a functionality if a user clicks on any column header it sorts the whole data according. How can I make sorting work on all my columns. Here is code excerpt that is storing the data:
And following is my jsp code:
Currently I am just sorting on Amount i.e. user clicks the Amount column to sort, how can I make the sort work for other columns i.e. if user clicks on Name column or Value column it sorts all the data.
Any help is appreciated.
Thanks
How do I sort data IN Ascending or Descending order. Following is a sample code. I want to sort on Amount i.e. float OR Value i.e. integer OR Name i.e. String. I am showing data in my app in table and want to provide a functionality if a user clicks on any column header it sorts the whole data according. How can I make sorting work on all my columns. Here is code excerpt that is storing the data:
Code:
.....................................
.......................................
Test t = null;
ArrayList a = new ArrayList();
t = new Test();
t.setAmount(23.89);
t.setVal(1);
t.setName("TestName1");
a.add(t);
t = new Test();
t.setAmount(54.00);
t.setVal(2);
t.setName("Name2");
a.add(t);
t = new Test();
t.setAmount(55.89);
t.setVal(3);
t.setName("Doe");
a.add(t);
..........................
.........................
And following is my jsp code:
Code:
.....................................
.......................................
ArrayList alist = (ArrayList)session.getAttribute("DataRecords");
Collections.sort(alist);
Comparator comp = Collections.reverseOrder();
Collections.sort(alist,comp);
..........................
.........................
Currently I am just sorting on Amount i.e. user clicks the Amount column to sort, how can I make the sort work for other columns i.e. if user clicks on Name column or Value column it sorts all the data.
Any help is appreciated.
Thanks