Re: Sorting using a DataTable
On Wednesday 30 January 2008, Karen Schaper escreveu: Hello, I am using a SortableDataProvider with a DefaultDataTable. From my understanding, it seems that for every column that I wish to sort on, I need to add code to the iterator method of the data provider. None of the columns were sorting and when I added some code in the iterator method (see below) I was able to sort on the street column. Is this the best way to sort columns? I am using wicket 1.3. it might be better to use that sorting info to get the data from the db in the right sort order. Thanks Karen iterator method from a SortableDataProvider public Iterator iterator( int first, int count ){ final SortParam sp = getSort(); EventList list = getInterruptionList(); if ( sp.getProperty().equals(street) ){ Collections.sort(list, new Comparator() { public int compare(Object arg0, Object arg1){ if ( sp.isAscending() ) return ((Interrupt)arg0).getStreet().compareTo(((Interrupt)arg1).getStreet()); else return ((Interrupt)arg1).getStreet().compareTo(((Interrupt)arg0).getStreet()); } }); } return list.listIterator( first ); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Sorting using a DataTable
Hello, I am using a SortableDataProvider with a DefaultDataTable. From my understanding, it seems that for every column that I wish to sort on, I need to add code to the iterator method of the data provider. None of the columns were sorting and when I added some code in the iterator method (see below) I was able to sort on the street column. Is this the best way to sort columns? I am using wicket 1.3. Thanks Karen iterator method from a SortableDataProvider public Iterator iterator( int first, int count ){ final SortParam sp = getSort(); EventList list = getInterruptionList(); if ( sp.getProperty().equals(street) ){ Collections.sort(list, new Comparator() { public int compare(Object arg0, Object arg1){ if ( sp.isAscending() ) return ((Interrupt)arg0).getStreet().compareTo(((Interrupt)arg1).getStreet()); else return ((Interrupt)arg1).getStreet().compareTo(((Interrupt)arg0).getStreet()); } }); } return list.listIterator( first ); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sorting using a DataTable
usually sorting is done in the database. if you get that list outside the database, then yes, you have to sort it using your own comparators. -igor On Jan 30, 2008 5:54 PM, Karen Schaper [EMAIL PROTECTED] wrote: Hello, I am using a SortableDataProvider with a DefaultDataTable. From my understanding, it seems that for every column that I wish to sort on, I need to add code to the iterator method of the data provider. None of the columns were sorting and when I added some code in the iterator method (see below) I was able to sort on the street column. Is this the best way to sort columns? I am using wicket 1.3. Thanks Karen iterator method from a SortableDataProvider public Iterator iterator( int first, int count ){ final SortParam sp = getSort(); EventList list = getInterruptionList(); if ( sp.getProperty().equals(street) ){ Collections.sort(list, new Comparator() { public int compare(Object arg0, Object arg1){ if ( sp.isAscending() ) return ((Interrupt)arg0).getStreet().compareTo(((Interrupt)arg1).getStreet()); else return ((Interrupt)arg1).getStreet().compareTo(((Interrupt)arg0).getStreet()); } }); } return list.listIterator( first ); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]