-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, guys! I have some trouble with scrollbar in the Listbox component - when I set the model to it and selecting several listitems, the scrollbar moves down to the last selected item, but I need to keep it on top. We've used simple zul as a view:
<zk>
<window xmlns="http: //www.zkoss.org/2005/zul" 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"
use="com.otr.sufd.zkossforms.table.SetDocColumnsView"
closable="true" border="normal" title="Customize columns" ctrlKeys="" height="400px" width="300px">
<borderlayout width="100%" height="100%">
<center>
<listbox id="table" checkmark="true" vflex="true" fixedLayout="true" multiple="true" width="100%">
<listhead>
<listheader align="left">Column title</listheader>
</listhead>
</listbox>
</center>
<south size="36" autoscroll="true">
<toolbar align="end">
<button label="OK" id="okButton" height="24px" width="75px" mold="os"/>
<button label="Reset" id="resetButton" height="24px" width="75px"/>
<button label="Cancel" id="cancelButton" height="24px" width="75px" mold="os"/>
</toolbar>
</south>
</borderlayout>
</window>
</zk>
In SetDocColumnsView I filled Listbox by model and make some AfterCompose actions:
public void configureView(List<? extends HeaderElement> columns, Set<String> hiddenIds) {
setSizable(true);
final ListModelList tableModel = new ListModelList(columns);
tableModel.setMultiple(true);
table.setModel(tableModel);
table.renderAll();
for (int i = 0; i < columns.size(); i++) {
final HeaderElement column = columns.get(i);
if (column != null) {
final Listitem listitem = table.getItemAtIndex(i);
listitem.setLabel(column.getLabel());
final String columnId = column.getId();
listitem.setValue(columnId);
listitem.setSelected(!hiddenIds.contains(columnId));
}
}
}
@Override
public void afterCompose() {
table = (Listbox) getFellow("table");
final Button okButton = (Button) getFellow("okButton");
//adds some listeners to buttons
addForward(Events.ON_OK, okButton, Events.ON_CLICK);
addForward(Events.ON_CANCEL, cancelButton, Events.ON_CLICK);
okButton.setFocus(true);
}
And then I show the dialog window by this code:
final SetDocColumnsView dialog = UIUtils.loadComponent(SetDocColumnsView.getUrl());
dialog.configureView(columnList, hiddenIds);
dialog.setPage(getPage());
dialog.doHighlighted();
I've tried to use some advice given in other threads, such as:
Clients.scrollIntoView(table.getItemAtIndex(0))
or call JS function inside my configureView method:
Clients.evalJavaScript("zk.Widget.$('" + dialog.table.getUuid() + "')._scrollToIndex(0);")
or keep all listitems what I need to select in a different Set and post to setSelectedItems method of Listbox, but everything is without success. Also, I've tried to debug a JS function _doScroll in Listbox.js but I don't figure out from where it has been called :(
I will be very appreciated if someone can help me with this problem.
Best regards, Roman
Thanks for the zkfiddle example.
Remove renderAll()
can solve scrolling position issue. Listbox by default will render necessary Listitem for visible range, you don't need to call renderAll()
which will enforce rendering all Listitems which is unnecessary for most cases.
Please refer to http://zkfiddle.org/sample/1a44bo/2-scrollbar-in-listbox-moves-to-last-selected-item#source-2
Since you use ListModelList
, you should select by ListModelList instead of Listitem
like:
ListModeList.addToSelection(headerElement)
please refer to
Thank you for the response, hawk!
I tried to change the selection of items as you advised, but it doesn't solve my problem - when I select several items via ListModeList.setSelection, the scrollbar moves down to the last item. I made an example of that behavior in zkfiddle - http://zkfiddle.org/sample/1a44bo/1-scrollbar-in-listbox-moves-to-last-selected-item
Asked: 2019-07-29 16:02:29 +0800
Seen: 19 times
Last updated: Aug 01 '19
if your example is simple, please paste it into http://zkfiddle.org/ so that anyone can have a look directly, this increases your chances of getting a response quickly
cor3000 ( 2019-07-29 18:30:05 +0800 )editYeah, I made simple zkfiddle example - http://zkfiddle.org/sample/1a44bo/1-scrollbar-in-listbox-moves-to-last-selected-item which reproduces the problem
anvibb ( 2019-07-30 21:16:58 +0800 )edit