0

Listheader events [closed]

asked 2013-01-29 12:14:21 +0800

pe4enko gravatar image pe4enko
13 1

Hi!

I have Listheader, and 2 event listener on it onSort and onClick But if i click on Listheader only onSort event fire. What i can do to get 2 events onSort and onClick?

Thanks.

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by sjoshi
close date 2013-02-08 05:55:27

Comments

I realized that when the sort event is not enabled the click event works, but when the sort event is enabled the click event stops working. Now why do you need the two events? one only is not sufficient for your case?

mhj ( 2013-01-29 14:34:24 +0800 )edit

My original problem is the following: I have Listbox which i want to sort by myself. After creating of Listbox. Listheader doesn't have sort arrow. Even if I call org.zkoss.zul.Listheader#setSortDirection(natural or ascending or descending), sort arrow not shown.

pe4enko ( 2013-01-29 16:21:52 +0800 )edit

It works only when i'll give sort='auto' in listheader. But at the same time when you click on a table column "onSort" event is generated.

To sort by multiple columns. I need to know whether a key Ctrl and Shift is pressed. In order not to reset the sorting already sorted columns.

pe4enko ( 2013-01-29 16:22:05 +0800 )edit

Can I get Ctrl and Shift key state when i have onSort Event?

pe4enko ( 2013-01-29 16:22:28 +0800 )edit

If I have onClick Event then in eventListener I have org.zkoss.zk.ui.event.MouseEvent and I can get keybord state. boolean controlDown = ((MouseEvent.CTRLKEY & event.getKeys()) == MouseEvent.CTRLKEY); boolean shiftDown = ((MouseEvent.SHIFTKEY & event.getKeys()) == MouseEvent.SHIFTKEY);

pe4enko ( 2013-01-29 16:22:43 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-02-05 11:22:06 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi pe4enko,

I have created a sample, is it you need?

<zk>

<label id="msg" value="msg"/>
<listbox width="150px">
    <listhead >
        <listheader id="header" label="column" sort="auto">
            <attribute name="onMySort"><![CDATA[
                Map data = (Map)event.getData();

                Boolean isAscending = org.zkoss.zk.au.AuRequests.getBoolean(data, "ascending");
                Boolean isCtrlKey = org.zkoss.zk.au.AuRequests.getBoolean(data, "ctrlKey");

                msg.value = 
                    (isAscending ? "Ascending": "Descending") + "\t"+
                    (isCtrlKey ? "CtrlKey": "NoCtrlKey");
            ]]></attribute>
        </listheader>
    </listhead>
    <listitem forEach="A,B,C" label="${each}"/>
</listbox>
<zscript><![CDATA[

    header.setWidgetOverride("doClick_", 
            "function (evt) {this.$doClick_(evt);" +
            "zAu.send(new zk.Event(this, 'onMySort', "+
            "{'': {ascending:'ascending' != this.getSortDirection(), "+
            "ctrlKey: evt.ctrlKey}}, {toServer:true}));}");
]]></zscript>

</zk>

link publish delete flag offensive edit

Comments

Yes, thanks!!!

pe4enko ( 2013-02-07 16:16:10 +0800 )edit
-1

answered 2013-01-30 07:57:45 +0800

nabil87 gravatar image nabil87
28 1 2

updated 2013-01-30 08:07:35 +0800

The first rule of event driven programming is:

"Never send more then one event per action."

So zk behaves as expected.

What you could do is, change the js of the Widget or DOM element
to always send the a ClickEvent or a costumized event.

Or you could send an evnt every time ctrl or shift is pressed released and
save the state at server-side.

read http://books.zkoss.org/wiki/ZK%20Client-side%20Reference/Communication/AU%20Requests/Client-side%20Firing (this) and http://www.w3schools.com/jsref/event_onkeypress.asp (that).

link publish delete flag offensive edit

Comments

living and learning, thanks!

mhj ( 2013-01-30 10:17:58 +0800 )edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-01-29 12:14:21 +0800

Seen: 84 times

Last updated: Feb 05 '13

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