-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
in a listbox with multiple=true and checkmark=true, if i manually select every listitem currently rendered,the "selectAll" checkbox in the listheader became automaticaly checked.
I need to disable that feature, is that possible?
many thanks
thank you sjoshi, here is my zul
greetings
<?xml version="1.0" encoding="UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./proposteEcopatList"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?link rel="stylesheet" type="text/css" href="/css/BDGZKStyles.css"?> <zk xmlns="http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <script type="text/javascript"><![CDATA[ zk.afterLoad('zul.sel', function () { //from http://www.zkoss.org/forum/listComment/13626 var _xListheader = {}; zk.override(zul.sel.Listheader.prototype, _xListheader, { _doClick: function (evt) { _xListheader._doClick.apply(this, arguments); //calls the original method (it selects all items) var $n = jq(evt.domTarget), cls = this.getZclass() + '-img-seld', cls2 = this.getZclass() + '-img-over-seld'; //calls onCheckAll from BDGListbox (true if check, false if uncheck) zAu.send(new zk.Event(this.parent.parent, 'onCheckAll',($n.hasClass(cls) || $n.hasClass(cls2)))); } }); }); ]]></script> <vlayout id="proposteEcopatList" apply="bdg.composer.proposte.ProposteEcopatListComposer" width="100%" height="100%" spacing="0" > <listbox id="listaProposteEcopat" model="@{proposteEcopatList$composer.listaEntita}" selectedItem="@{proposteEcopatList$composer.selectedEntita}" mold="paging" pageSize="20" emptyMessage="nessun record presente" multiple="true" checkmark="true" forward="onSelect=proposteEcopatList.onSelect, onAfterRender=proposteEcopatList.onAfterRender" use="bdg.zk.component.BDGListbox"> <listhead sizable="true"> <listheader id="lhCheck" /> <listheader id="lhFattori" label="Fattore" hflex="min"/> <listheader id="lhCentri" label="Centro" hflex="min"/> <listheader id="lhProgetti" label="Progetto" hflex="min"/> <listheader id="lhObiettivi" label="Obiettivo" hflex="min"/> <listheader id="lhAttivita" label="Attivita" hflex="min"/> <listheader id="lhCommesse" label="Commesse" hflex="min"/> <listheader id="lhFontiFinanziamento" label="Fonti Finanziamento" hflex="min"/> <listheader id="lhPoliticheProcessi" label="Politiche Processi" hflex="min"/> <listheader label="Importo" width="100px"/> </listhead> <listitem self="@{each=propostaEp}" value="@{propostaEp}" forward="onDoubleClick=proposteEcopatList.onEdit" sclass="bdg-listcell"> <listcell/> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaFattoreToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToFattore'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaCentroToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToCentro'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaProgettoToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToProgetto'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaObiettivoToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToObiettivo'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaAttivitaToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToAttivita'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaCommessaToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToCommessa'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaFonteFinanziamentoToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToFonteFinanziamento'}"/> </hlayout> </listcell> <listcell> <hlayout> <image src="@{propostaEp converter='bdg.zk.converter.EntitaPoliticaProcessoToImgTipoEntita'}"/> <label value="@{propostaEp converter='bdg.zk.converter.ObjectToPoliticaProcesso'}"/> </hlayout> </listcell> <listcell> <decimalbox value="@{propostaEp.importo}" inplace="true" readonly="true" format="#0.00"/> </listcell> </listitem> </listbox> </vlayout> </zk>
Please post the result of this Demo Code to me...
<zk> <listbox checkmark="true" mold="paging" pageSize="5"> <custom-attributes org.zkoss.zul.listbox.rod="true" /> <listhead> <listheader label="Name1" /> <listheader label="Address" /> </listhead> <zk forEach="1,2,3,4,5,6,7,8,9"> <listitem> <listcell label="Name ${each}"></listcell> <listcell label="Address ${each}"></listcell> </listitem> </zk> </listbox> <listbox multiple="true" checkmark="true" mold="paging" pageSize="10"> <custom-attributes org.zkoss.zul.listbox.rod="true" /> <listhead> <listheader label="Name2" /> <listheader label="Address2" /> </listhead> <zk forEach="1,2,3,4,5,6,7,8,9"> <listitem> <listcell label="Name ${each}"></listcell> <listcell label="Address ${each}"></listcell> </listitem> </zk> </listbox> </zk>
And ,you Wired your Listbox with the Java Code and setting value from there also?
Hi sjoshi,
i tested your demo code:
- first listbox has no multiple attribute, so the result is a listbox with radio buttons, i thought it was a typo so i added multiple="true" (on first listbox),
what i got is a listbox with checkbox but no selectall checkbox on header (dont know why), if i manually select every record on both pages, nothing happens
- second listbox has the same behaviour as the one i posted earlier, it's a listbox with checkmarks, and a selectAll checkmark on header,
if i check the selectAll mark, all items are selected (which is expected), but if i select every items, the selectAll checkmark became selected (this is the behaviour i would like to remove)
>And ,you Wired your Listbox with the Java Code and setting value from there also?
Yes, the model bound to the listbox is loaded in my java composer, and it contains the exact number of elements that the listbox shows in a single page
(pagination is managed by my composer cause i have huge amounts of data to load).
What i suppose is happening (thanks to your example) is that if a model contains a certain number of element, and if i show all that elements in a single page of the listbox, when i check every items the selectAll check became checked. Actually that won't be a wrong behaviour, but still i need to remove it (because i'm extending listbox component to manage selection on multiple pages)
thanks for your help
In demo example i removed
multiple=true
from first listbox intentionally .
About your this point
what i got is a listbox with checkbox but no selectall checkbox on header (dont know why), if i manually select every record on both pages, nothing happens
I am able to view the selectall button in header of the Listbox.I do not know why you are not able to see Selectall button in header.And Selectall button is unchecked when page is loaded .When i am clicking on this checkbox only then all items are selected for me.
1-Do you mean this ,even in this simple example you are not able to see selectall checkbox?
2-What is the ZK version you are using in your environment.
3-Did u tried this..With your Wired Listbox
mylistbox.setMultiple("true"); mylistbox.setCheckmark("true");
rather than inside ZUL page.
Hi,
>> what i got is a listbox with checkbox but no selectall checkbox on header (dont know why), if i manually select every record on both pages, nothing happens
>I am able to view the selectall button in header of the Listbox.
>I do not know why you are not able to see Selectall button in header.
>And Selectall button is unchecked when page is loaded .
>When i am clicking on this checkbox only then all items are selected for me.
That is correct, but when the Selectall button is unchecked, what happens if you manually check al listitem in the listbox? do the selectall button became checked?
> 1-Do you mean this ,even in this simple example you are not able to see selectall checkbox?
Yes, in the first listbox, the one with items on 2 pages, i can't see the selectall checkbox.
In the second listbox, the one with only onepage, i can see the selectall checkbox, and it has the normal behaviour
So I tried to remove rod deleting the following line
<custom-attributes org.zkoss.zul.listbox.rod="true" />
from the first listbox, and the selectall checkbox did appear! But it has the same behaviour (if i check all items in a page, it become checked)
> 2-What is the ZK version you are using in your environment.
I'm using zk 6.0
> 3-Did u tried this..With your Wired Listbox
> mylistbox.setMultiple("true");
> mylistbox.setCheckmark("true");
> rather than inside ZUL page.
i tried but nothing changed
thank you
Hi,
If you will checked all the Chekbox then selectall checkbox will automatically checked its ZK feature .But if you are using pagination and you checked all the the checkobox manually it will automatically check selectall checkbox but for that page only if you will go to next page i mean 2nd page the item will not be selected .I am not confirm why you dont want selectall button will unchecked even user selected all the chekbox of current page?
Hi sjoshi, I know it's a ZK feature,
the reason why i need to disable it, is because I've extended the zk listbox component to manage selection over multiple pages, and the selectAll button need to be checked only if every item on every pages is checked, not only when the items on a single page are selected.
I just need some advice on what function i need to overwrite or what event i need to intercept to disable that feature.
thank you for your help
Implement an own checkAll mechanism in your ItemRenderer.
All code pieces are in the custom ListItemRenderer class.
Listhead listhead = new Listhead(); listhead.setParent(lb); // Delete marker Checkbox lh = new Listheader(); lh.setWidth("55px"); lh.setParent(listhead); hbox = new Hbox(); hbox.setParent(lh); ckbDeleteAll = new Checkbox(); ckbDeleteAll.setParent(hbox); ckbDeleteAll.setChecked(false); ckbDeleteAll.setStyle("padding-left: 2px; padding-right: 3px;"); ckbDeleteAll.setTooltiptext("select all items for deleting "); ckbDeleteAll.addEventListener("onCheck", new CheckAllListener()); img = new Image(); img.setSrc(imgTrash); img.setParent(hbox);
@Override public void render(Listitem item, Object data) throws Exception { MyBean obj = (MyBean) data; Listcell lc; Image img; Label lb; Checkbox cb; A a; // Delete Checkbox lc = new Listcell(); cb = new Checkbox(); cb.setParent(lc); cb.setChecked(false); cb.setStyle("padding-left: 3px;"); cb.setTooltiptext("check it for delete"); . . .
/** * Inner Listener class.<br> * onCheck for the 'mark all for deleting' Checkbox. * * @author Stephan Gerth */ private final class CheckAllListener implements SerializableEventListener { private static final long serialVersionUID = 1L; @Override public void onEvent(Event event) throws Exception { Checkbox ckb = (Checkbox) event.getTarget(); if (ckb.isChecked()) checkAllItems(true); else checkAllItems(false); } }
/** * EN: Checks/unchecks all items as marked for deleting.<br> * DE: Checked/unChecked alle Datensetze als zum loeschen markiert.<br> */ @SuppressWarnings("unchecked") public void checkAllItems(boolean checkAll) { List<Listitem> list = lb.getItems(); if (list.size() > 0) { for (Listitem li : list) { if (li.getFirstChild().getFirstChild() instanceof Checkbox) { Checkbox cb = (Checkbox) li.getFirstChild().getFirstChild(); cb.setChecked(checkAll); } } } }
/** * EN: Deletes the records which checkbox is marked for delete.<br> * DE: Loescht alle zum loeschen markierten Datensaetze.<br> */ @SuppressWarnings("unchecked") public void deleteMarkedItems() { List<Listitem> list = lb.getItems(); if (list.size() > 0) { for (Listitem li : list) { if (li.getFirstChild().getFirstChild() instanceof Checkbox) { Checkbox cb = (Checkbox) li.getFirstChild().getFirstChild(); if (cb.isChecked()) { Call entity = (Call) li.getValue(); // Your delete stuff here getMyDBService().delete(entity); } } } } }
best
Stephan
Asked: 2012-09-25 14:57:08 +0800
Seen: 770 times
Last updated: Mar 21 '13