setComparator did not refresh PopUp

Issue #31 resolved
Former user created an issue
When I set a Comparator for a editor with

filterHeader.getFilterEditor(4).setComparator(new ColumnSorterDateAsStringComparator());

the conten of the popup ist not sorted by this compartor.

I changed the following in FilterEditor and everything works fine. I dont have much
experience with your lib but maybe zhis is an error.

    /** IFilterEditor method. */
    @Override public void setComparator(Comparator comparator) {
        // the comparator is used for sorting rendered choices, and for
        // comparison operations on the text parser
        if ((comparator != this.comparator) && (comparator != null)) {
            this.comparator = comparator;

            ChoiceRenderer lcr = getRenderer();
            if (lcr == null) {
//            else {
//                popup.setRenderedContent(lcr, comparator);
//                requestChoices();
//            }
            // do this alway !!!
            popup.setRenderedContent(lcr, comparator);

Original issue reported on by arndt.schoenberg on 2012-11-26 12:29:56

Comments (5)

  1. coderazzi coderazzi repo owner
    Hi, could you give some details on the way you are using the table filter?
    1- In your table model, which class is associated to the column 4? Is a Date or is
    a String?
    2- Could you include your ColumnSorterDateAsStringComparator code?

    Original issue reported on by coderazzi on 2012-11-27 13:16:25

  2. Former user Account Deleted
    Hi Lu,
    i had much problems using date so i dicedid to use string in the model. The date field
    is converted in a string.
    After creating the empty table and some user actions data is put into the table. In
    the popup the item are correct but not ordered.
    The comparator ist also used in the sorter and works fine
    Kind regards,
    public class ColumnSorterDateAsStringComparator implements Comparator<String> {
        private static SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
        public ColumnSorterDateAsStringComparator() {
        public int compare(String o1, String o2) {
            if (o1 == null || o1.isEmpty()) {
                return 1;
            if (o2 == null || o2.isEmpty()) {
                return -1;
            try {
                return sdf.parse(o1).compareTo(sdf.parse(o2));
            } catch (ParseException e) {
            return -1;

    Original issue reported on by arndt.schoenberg on 2012-11-28 06:26:49

  3. coderazzi coderazzi repo owner
    Hi, Arndt,
    the popup items in the editor are always treated as Strings. In your specific example,
    the comparator on the popup items will compare Strings with Strings, which is obviously
    fine. If your table model had used Date instances instead of Strings, you would have
    been greeted with nice exception backtraces :-) 
    Now, using String instead of Date in the table model is probably not the best; in the
    filter header, for example, you will be able to enter ">1", which makes no sense for
    Dates, but does for Strings. Also, performance-wise, is a big hit if the user decides
    to sort on that column (with the filter or just buy sorting the table itself), as there
    would be a lot of conversions from String to Date internally. 
    Anyway, you have your very valid reasons to use Strings, so this is not the point for
    this issue: but your patch would work only for columns with String content. 
    BUT it does not work completely: dates are indeed shown in the choice box correctly
    sorted (date-wise), but the choice box expects the content to be alphabetically sorted.
    This is required for navigation (when you enter '1' it automatically lists all entries
    starting with 1, that should be consecutive) but also for autocompletion. In general,
    it would be difficult now to change the behavior for the choice box to expect unsorted
    I guess that the point for you is: how to handle correctly dates in the filter editor,
    for dates to appear correctly sorted on the choice box?
    One answer is to use a formatter yyyy.MM.dd instead of dd.MM.yyyy (FilterSettings.dateFormat
    can be used for this as well). With this, the alphabetic order is the same as the natural
    This answer is probably wrong if your business model requires dates to have that very
    specific format. Unfortunately, there is currently no alternative in the filter editor
    to handle this case; as I said, it affects a few algorithm's logic and a solution requires
    much more work that the patch you suggested.
    I am writing a new issue to cover this scenario, using a different subject: "Allow
    different sorting on choices box".
    Best regards,

    Original issue reported on by coderazzi on 2012-11-28 13:04:58

  4. coderazzi coderazzi repo owner
    Hi, I have in fact started work on this issue. Elements in the popup are not treated
    now as Strings, but as the associated column's type.
    I have commited the changes into the repository, although the code is not yet final:
    it works as expected, just the API is not yet final.
    You can try it by downloading directly the code at the google site
    ( If you
    do so, you still need to do, on the columns where you expect natural
    ordering: getFilterEditor().setAlphabeticalOrderOnChoices(false);
    Again: the API will most likely change before release.

    Original issue reported on by coderazzi on 2012-12-18 10:34:26

  5. coderazzi coderazzi repo owner
    So, in the new release 5.0.0 choices are automatically sorted using the comparator for
    the associated class. This is the default behaviour. It is possible to define different
    comparators for the choices, which can be interesting to use, for example, inverse
    sorting on dates, etc.
    To revert to the original status (sorting alphabetically), it is needed to set the
    choices comparator to null.

    Original issue reported on by coderazzi on 2013-03-12 23:09:48

  6. Log in to comment