0

Listbox Sorting (Sorting with Live Data)

asked 2014-04-17 17:11:25 +0800

orthello gravatar image orthello
18 2

I'm using the sort(Comparator,boolean) method of ListModel. How do I get the "ascending" and "decending" arrow icons to show up? The arrows do not show up at all but the ListModel does re-sort and display correctly. I just need the "ascending" and "decending" icons to also show up.

delete flag offensive retag edit

Comments

do you have defined sort in your columnsheaders?

chillworld ( 2014-04-18 05:23:40 +0800 )edit

Yes, see below.

orthello ( 2015-05-08 00:25:45 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-09-28 14:40:25 +0800

Darksu gravatar image Darksu
1991 1 4

Hello orthello,

A working example of a listbox with sort by comparator can be found at the following url:

http://www.zkoss.org/zkdemo/listbox/sortbycomparator

Here the arrows work as expected, thus could you please cross-check the example with your code?

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

This example was not helpful enough. I (with the help of the kind zk folks) figured it out eventually. The problem I was having had to do with a full MVVM scenario. This example had all the code in the zul -- not good. A full example of sorting in MVVM would have uncovered my problems.

orthello ( 2015-05-08 00:04:27 +0800 )edit
0

answered 2015-05-08 00:19:54 +0800

orthello gravatar image orthello
18 2

updated 2015-05-08 00:22:53 +0800

Code is below. My Comparators are being changed dynamically. That means that I needed serveral NotifyChanges to take place (and have their effect on the screen) before I called sort. binder.postCommand() was how I allowed those NotifyChanges to take place (and be processed) before sorting. ZK staff helped me with this. Thanks!

Do you believe it? All of that just to get the up and down arrows on the column headers to show up. #DontLikeDisappearingColumnHeaderArrows

@Command ( "updateNameDisplayFormat" )
    public void doUpdateNameDisplayFormat (
        @BindingParam ( "format" ) String format,
        @ContextParam ( ContextType.BINDER ) Binder binder )
    {
        cNameDisplayFormat = format;

        // Set to ascending order every time format is changed
        cCurrentSortDirection = true;

        logToAppLog ( Level.DEBUG, "Name Display Format: " + format );

        if ( getIsLastFirstDisplayFormat () )
        {
            cCurrentFullNameComparator =
                new PanelJurorLastNameFirstNameComparator ();
        }
        else
        {
            cCurrentFullNameComparator =
                new PanelJurorFirstNameLastNameComparator ();
        }

        BindUtils.postNotifyChange ( null, null, this, "nameDisplayFormat" );
        BindUtils.postNotifyChange ( null, null, this, "lastName" );
        BindUtils.postNotifyChange ( null, null, this, "firstName" );
        BindUtils.postNotifyChange ( null, null, this,
            "fullNameAscendingComparator" );
        BindUtils.postNotifyChange ( null, null, this,
            "fullNameDescendingComparator" );

        // http://forum.zkoss.org/question/89540/wrong-scrollbar-position-when-clear-listbox-items/
        // http://tracker.zkoss.org/browse/ZK-1834
        // For the scrollbar on the listbox to behave perfectly
        // we need to upgrade ZK to version 6.5.5 when it becomes
        // available.
        // If user changes name display then a re-sort is implied
        // Always send true (ascending order)
        // Every time the display format is changed we want sort to start off
        // as ascending
        // This means that all decending sorts will be done through
        // the listheader
        binder.postCommand (
            "sortPanelJurorListModel",
            Collections.<String, Object>singletonMap (
                "ascending", cCurrentSortDirection ) );
    }

    @Command ( "sortPanelJurorListModel" )
    public void doSortPanelJurorListModel (
        @BindingParam ( "ascending" ) boolean isAscending )
    {
        // It is surpremely important that getFullNameAscendingComparator and
        // getFullNameDecendingComparator methods be called instead of
        // referencing class variables due to the event timing of the
        // NotifyChanges in doUpdateNameDisplayFormat

        if ( isAscending )
        {
            cPanelJurorListModel.sort (
                getFullNameAscendingComparator (),
                isAscending );
        }
        else
        {
            // As code sits now will never get here
            cPanelJurorListModel.sort (
                getFullNameDescendingComparator (),
                isAscending );
        }
    }
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-04-17 17:11:25 +0800

Seen: 29 times

Last updated: May 08 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More