ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

demand for listbox multiple mold can listen the header checkbox check event

yuzexu_zk
2 Sep 2010 01:01:42 GMT
2 Sep 2010 01:01:42 GMT

i want add listen at the listbox header checkbox checkEvent is useful

or
can remove the zk default checkbox then add self checkbox

jimmyshiau
8 Sep 2010 22:28:40 GMT
8 Sep 2010 22:28:40 GMT

Hi
You can't replace checkbox

I created a sample

<zk xmlns:w="http://www.zkoss.org/2005/zk/client">
	<listbox multiple="true" checkmark="true">
		<listhead>
			<listheader label="Name" onUser='alert(org.zkoss.lang.Objects.toString(event.data));'>
				  <attribute w:name="_doClick"><![CDATA[
					function (evt) {
						this.$_doClick(evt); //call the original method
						var $n = jq(evt.domTarget),
	                  		cls = this.getZclass() + '-img-seld',
	                  		cls2 = this.getZclass() + '-img-over-seld';
		                  
						zAu.send(new zk.Event(this, 'onUser',($n.hasClass(cls) || $n.hasClass(cls2))));
		            }
            ]]></attribute>
				
			</listheader>
			<listheader label="Gender" />
			<listheader label="Age" />
		</listhead>
		<listitem>
			<listcell label="Mary" />
			<listcell label="FEMALE" />
			<listcell label="18" />
		</listitem>
		<listitem>
			<listcell label="John" />
			<listcell label="MALE" />
			<listcell label="20" />
		</listitem>
	</listbox>
</zk>

NeusTop Contributor
16 Jan 2012 10:45:59 GMT
16 Jan 2012 10:45:59 GMT

Hi,
I was looking to listen to multiple listbox checkmark too.

But it is not working completly well...
If I check the box in a page, go to another page check the box too and return to the first page and try to deselect the checkbox I have to click the box twice. I print the data that is returning the event and the first time I click the box it stills return true. The second time it works well and returns false.

It's happening to you too??

I copy Jimmy's code but instead of sending the event to the header I'm sending it to the listbox:

<attribute w:name="_doClick"><![CDATA[
	//Creamos el evento onCheckTodos para saber cuando se seleccionan/deseleccionan todas las
	//filas del listbox utilizando el checkbox (leído en el foro http://www.zkoss.org/forum/listComment/13626)
	function (evt) {
		this.$_doClick(evt); //call the original method
		var $n = jq(evt.domTarget),
		cls = this.getZclass() + '-img-seld',
		cls2 = this.getZclass() + '-img-over-seld';
		//Pasa como data del evento true si se ha marcado el check para seleccionar y false si se ha desmarcado 
							
		zAu.send(new zk.Event(<b >this.parent.parent</b>, 'onCheckTodos',($n.hasClass(cls) || $n.hasClass(cls2))));
     }
]]></attribute>

And I'm listening it in the composer

public void onCheckTodos$LBPunteros(ForwardEvent event){
		//Este evento contiene en sus datos true si se ha marcado el checkbox para seleccionar
		//todos y false si se ha desmarcado apra deseleccionar todos los items.
		//Si se quiere desmarcar todos los items (los datos del evento contienen false)
		//desmarcamos todos los items del listbox no solo de la página.
		System.out.println("origin--> " + (Boolean)event.getOrigin().getData());
	
}

jimmyshiau
6 Feb 2012 11:55:50 GMT
6 Feb 2012 11:55:50 GMT

Hi Neus,

You can try to remove all of w:name attribute, and add the following script:

<script type="text/javascript"><![CDATA[
		zk.afterLoad('zul.sel', function () {
			var _xListheader = {};
			zk.override(zul.sel.Listheader.prototype, _xListheader, {
				_doClick: function (evt) {
					_xListheader._doClick.apply(this, arguments); //call the original method
					var $n = jq(evt.domTarget),
					cls = this.getZclass() + '-img-seld',
					cls2 = this.getZclass() + '-img-over-seld';
					//Pasa como data del evento true si se ha marcado el check para seleccionar y false si se ha desmarcado 
										
					zAu.send(new zk.Event(<b >this.parent.parent</b>, 'onCheckTodos',($n.hasClass(cls) || $n.hasClass(cls2))));
				}
			});
		});
	]]></script>