| Issue 33: | Nullable column sorting behavior should be configurable? | |
| 3 people starred this issue and may be notified of changes. | Back to list |
Currently, when sorting nullable columns, nulls are always considered to be "less than" any other value. In many applications, however, the expected behavior is that nulls should always be last regardless of whether sort order is ascending or descending. This allows users to compare meaningful values without first having to wade through a number of blank lines. I had to modify org.jmesa.core.sort.MultiColumnSort to get this behavior for my application. I've pasted my modified version below... you may want to consider making this behavior the default, or at least making the option available to the user. Thanks! -Ryan /* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jmesa.core.sort; import java.util.Collection; import java.util.Collections; import java.util.List; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.collections.comparators.ComparatorChain; import org.apache.commons.collections.comparators.NullComparator; import org.jmesa.limit.Limit; import org.jmesa.limit.Order; import org.jmesa.limit.Sort; import org.jmesa.limit.SortSet; /** * @since 2.0 * @author Jeff Johnston */ public class MultiColumnSort implements ColumnSort { @SuppressWarnings("unchecked") public Collection sortItems(Collection<Object> items, Limit limit) { ComparatorChain chain = new ComparatorChain(); SortSet sortSet = limit.getSortSet(); for (Sort sort : sortSet.getSorts()) { if (sort.getOrder() == Order.ASC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator(true))); //changed from NullComparator() } else if (sort.getOrder() == Order.DESC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator(false)), true); //changed from NullComparator() } } if (chain.size() > 0) { Collections.sort((List) items, chain); } return items; } }
Oct 15, 2007
#1
extremec...@gmail.com
Status:
Accepted
Oct 16, 2007
Turns out custom sorting is a hot issue! Sorting is already plugable, but I still need to provide the hooks to make this available through the TableFacade and tags. I will work on that. It will be available in the 2.3 release, and also accessible through an incremental build...hopefully within a week!
Labels:
-Type-Defect -Priority-Medium Type-Enhancement Priority-High
Oct 22, 2007
Have the ColumnSort interface plugable through the TableFacade and tags now. Still doing more testing, but the implementation is done now.
Status:
Started
Oct 23, 2007
The changes are all done. If you would like to get an early release you can get it from http://builds.jmesa.org/. This is a solid build so you would be fine to use it. Just use the columnSort attribute on the tableFacade and give the fully qualified path to your ColumnSort class.
Status:
Fixed
Jan 29, 2008
Reopened issue because this should be configurable in the Preferences....
Status:
Accepted
Labels: -Priority-High Priority-Medium |