-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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>
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).
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 )editMy 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 )editIt 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 )editCan I get Ctrl and Shift key state when i have onSort Event?
pe4enko ( 2013-01-29 16:22:28 +0800 )editIf 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