0

MVVM List item, default sorting with icon

asked 2012-06-16 08:38:04 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi
As per the requirment, i need to sort by default based on column say lastname and i want to show the default icon given by zk.
Can someone help me on this.

Please note: List items are loaded from the DB when the page is loaded. After that user can click any header to sort. This part is working fine.
But i need to sort by default and i need to show that icon also.


<?page title="Listitem MVVM Demo with Hibernate" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Listitem MVVM Demo with Hibernate" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('myvm') @init('domainVMS.PersonVM')">
<listbox id="test" model="@load(myvm.allPersons)"
selectedItem="@bind(myvm.curSelectedPerson)">
<listhead sizable="true">
<listheader label="First Name" width="400px" sort="auto(firstName)"/>
<listheader label="Last Name" width="285px" sort="auto(lastName)"/>
<listheader label="email" width="285px" sort="auto(email)"/>
</listhead>
<template name="model" var="p1">
<listitem onDoubleClick="@command('onDoubleClicked')">
<listcell label="@load(p1.firstName)" />
<listcell label="@load(p1.lastName)" />
<listcell label="@load(p1.email)" />
</listitem>
</template>
</listbox>
</window>
</zk>

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-06-18 11:42:06 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Any help please................

link publish delete flag offensive edit

answered 2012-06-18 13:13:08 +0800

madruga0315 gravatar image madruga0315 flag of Brazil
937 2 12

Hi Senthil.

I believe that the easiest way to achieve this:

1st: On the first access to the page, fetch the data from the DB already sorted (say by lastname ascending)

2nd: On your zul: <listheader label="Last Name" width="285px" sort="auto(lastName)" sortDirection="ascending"/>


Another way would be using a Composer along side the ViewModel, and in the Composer you could trigger the onClick event on top of the listheader that should be sorted...

HTH,
Madruga

link publish delete flag offensive edit

answered 2012-06-18 13:17:35 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Perfect. Method 1 works fine. So let me follow that.

Thank you madruga. Your reply is very helpful.

Senthil M

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-06-16 08:38:04 +0800

Seen: 274 times

Last updated: Jun 18 '12

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