0

Listbox auto sorted column after ListModel Update

asked 2017-02-17 07:51:28 +0800

jomir gravatar image jomir
0

Hi, I have a Listbox with a ListModel. I set the model on doAfterCompose then update the model from a timer component. The Listbox have a sort Comparator for each column. The problem is, when a column is sorted (ascending/descending) then the refresh event add a row of data, the data is appended as the last element of row and not sorted according to the column selected. How do I add a row then sort it automatically?

logs.zul

<?init class="AuthenticationInit"?>
<zk>
<zscript>
<![CDATA[
import java.util.Comparator;
import com.akarprima.dao.model.JobStatus;
import com.akarprima.util.JobStatusComparator;
Comparator nameAsc = new JobStatusComparator(true, JobStatusComparator.NAME);
Comparator nameDsc = new JobStatusComparator(false, JobStatusComparator.NAME);
Comparator dateAsc = new JobStatusComparator(true, JobStatusComparator.DATE);
Comparator dateDsc = new JobStatusComparator(false, JobStatusComparator.DATE);
Comparator sessionAsc = new JobStatusComparator(true, JobStatusComparator.SESSION);
Comparator sessionDsc = new JobStatusComparator(false, JobStatusComparator.SESSION);
Comparator sTimeAsc = new JobStatusComparator(true, JobStatusComparator.START_TIME);
Comparator sTimeDsc = new JobStatusComparator(false, JobStatusComparator.START_TIME);
Comparator eTimeAsc = new JobStatusComparator(true, JobStatusComparator.END_TIME);
Comparator eTimeDsc = new JobStatusComparator(false, JobStatusComparator.END_TIME);
Comparator durationTimeAsc = new JobStatusComparator(true, JobStatusComparator.DURATION);
Comparator durationTimeDsc = new JobStatusComparator(false, JobStatusComparator.DURATION);
   ]]>
</zscript>
<window border="none"
    apply="JobLogController">
    <label id="message" />
    <listbox id="jobLog" height="100%" sizedByContent="true"
        span="true">
        <listhead>
            <listheader label="No" />
            <listheader label="Date" sortAscending="${dateAsc}"
                sortDescending="${dateDsc}" />
            <listheader label="Session"
                sortAscending="${sessionAsc}" sortDescending="${sessionDsc}" />
            <listheader label="Job Name" sortAscending="${nameAsc}"
                sortDescending="${nameDsc}" sortDirection="ascending" />
            <listheader label="Start" sortAscending="${sTimeAsc}"
                sortDescending="${sTimeDsc}" />
            <listheader label="Finish" sortAscending="${eTimeAsc}"
                sortDescending="${eTimeDsc}" />
            <listheader label="Running Time"
                sortAscending="${durationTimeAsc}"
                sortDescending="${durationTimeDsc}" />
        </listhead>
        <template name="model">
            <listitem>
                <listcell label="${forEachStatus.index + 1}" />
                <listcell label="${each.value.date}" />
                <listcell label="${each.value.session}" />
                <listcell label="${each.value.jobName}" />
                <listcell label="${each.value.startTime}" />
                <listcell label="${each.value.endTime}" />
                <listcell label="${each.value.duration}" />
            </listitem>
        </template>
    </listbox>
    <timer id="timer" delay="5000" repeats="true" />
</window>
   </zk>

JobLogController.java

enter code here
package com.akarprima.idx.controller.daily;

public class JobLogController extends SelectorComposer<Component> {
private static final long serialVersionUID = 4463081939576759090L;
AppJobStatusDAO ajdao = new AppJobStatusDAO();

@Wire
private Listbox jobLog;

private ListModelMap<String, JobStatus> jd = new ListModelMap<String, JobStatus>();

@Override
public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);
    jobLog.setModel(jd);
    refresh();
}

@Listen("onTimer = timer")
public void refresh() {
    AppUtils.compareAddMap(jd, ajdao.getJobLogDailyMap());
}
    }
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-02-22 06:47:31 +0800

Darksu gravatar image Darksu
1976 1 4

Hello jomir,

Please refer to the following documentation, and specifically to the section "The On Sort Event", and "The Sort Method".

https://www.zkoss.org/wiki/ZKComponentReference/Data/Listbox

It shows how to accomplish your task.

Best Regards,

Darksu

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: 2017-02-17 07:51:28 +0800

Seen: 27 times

Last updated: Feb 22