-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a big list and I want to select an item in this list and then scroll the list to this selected item.
I read a lot of message discussing about this issue but no correct solution was given.
The item is correctly selected but I have to scroll myself to this selection.
Using height instead of row doesn't work, I am using Zk 3.5.2.
I have the listbox in the zul:
<listbox id="transactionsList" context="editTransaction" row="50" forward="onSelect=onTransactionSelected"> <listhead sizable="true"> <listheader align="center" label="Date" /> <listheader align="center" label="Tiers" /> <listheader align="center" label="Débit" /> <listheader align="center" label="Crédit"/> <listheader align="center" label="Solde"/> </listhead> </listbox>
I am using a GenericAutowireManager which build the list and the model
protected Listbox transactionsList; protected ListModelList model; public void onCreate(CreateEvent event){ super.onCreate(event); model = new ListModelList(); transactionsList.setModel(model); transactionsRenderer = getTransactionListRenderer(); transactionsList.setItemRenderer(transactionsRenderer); } public void onLoadTransactions (TransactionListEvent event){ List<Transaction> transactions = event.getTransactions(); initBalance = event.getInitBalance(); model.clear(); if(transactions.size()>0){ model.addAll(transactions); Transaction transaction = event.getTransaction(); if(transaction==null){ transactionsList.setSelectedIndex(model.getSize()-1); } else{ int index = model.indexOf(transaction); if(index!=-1){ transactionsList.setSelectedIndex(index); } } } }
Hi jdeboer,
I had the same problem with FF 3 and I opened a bug (it is already fixed but not release in a new version).
You could try to get the fix from ZK svn or use a javascript fix:
fixZk.js:
function fixListScroll(itemId) { // Do it asynchronies since ZK still manipulate the list, by setting the timeout to 0 // we cause the execution to take place immediately after ZK finish it own process. setTimeout("fixListScrollDirect('" + itemId + "')", 0); } function fixListScrollDirect(itemId) { var item = $e(itemId); if (!item) { alert("No item"); return; } var list = item.parentNode.parentNode.parentNode; var viewSize = list.scrollHeight; var scrollMax = viewSize - list.offsetHeight; if (scrollMax <= 0) { // no scroll return; } var itemTop = item.offsetTop; var itemBottom = itemTop + item.offsetHeight; var itemMiddle = itemTop + item.offsetHeight/2; var viewTop = list.scrollTop; var viewBottom = viewTop + list.offsetHeight; if (viewBottom <= itemMiddle || itemBottom <= itemMiddle) { // item not in view, scroll so it will be in the middle of the view list.scrollTop = Math.max(0, Math.min(scrollMax, itemTop - (list.offsetHeight - item.offsetHeight)/2)); } else { // make sure that all the item is viewable var delta = 0; if (itemBottom > viewBottom) { dalta = itemBottom - viewBottom; viewTop += delta; viewBottom += delta; } if (itemTop < viewTop) { delta -= (viewTop - itemTop); } list.scrollTop += delta; } }
Clients.response(new AuScript(transactionsList, "fixListScroll('" + transactionsList.getSelectedItem().getUuid() + "')"));
of course in the zul page you have to inclue the fixZk.js:
<script type="text/javascript" src="/js/fixZk.js"/>
Maybe there are better ways to do it, but currently this works great for me.
Hanan
I have just downloaded zk 3.6.0 (which was just released few days ago) and the bug is still there. I am wondering if zk is a mature product. I found another bug (which in my opinion is really annoying). It is impossible to select some date like 25th Feb (with the datebox component). It displays 25th of March. At this point, zk is really unusable for me...
The datebox was recently fixed. Finally, it occured only with the format date ( dd MMM yyyy) with MMM is the month name (Jan, Feb ...) and I think only with the locale FR. Probably caused by the fact that in French, some month have accents (such as Fév, Déc....).
However, the autoscroll bug is still opened and no one seems to be in charge. That is more annoying...
Hi,
Please refer to the discussion
http://www.zkoss.org/forum/index.zul#path%3DlistComment%3BdiscussionId%3D7169%3BcategoryId%3D14%3B
The last message may help.
Asked: 2009-02-12 20:06:59 +0800
Seen: 496 times
Last updated: Mar 30 '09