# Calculate how many lines fits in a listbox

Neus
1415 14

Hi,
I'm trying to calculate how many lines fits in a listbox using javascript.
I can obtain the height of the listbox, the height of one line and with these data make the calculation.
My problem is that I can't listen when the listbox is resized. I'm able to know when the browser is resized but sometimes the listbox is resized for other reasons (another component that expands and do the listbox smaller, etc.

Is there a way to know when the height of a listbox has changed??
How does ZK know it?? (because they are recalculating how many lines fits in a listbox everytime the listbox is resized)

Thank you!

delete retag edit

## 6 Replies

jimmyshiau
4921 5
http://www.zkoss.org/

Hi Neus,

The only way is to override the client onSize function, when the listbox resize, the onSize function will be call

listbox.setWidgetOverride("onSize",
"function () {this.\$onSize();zk.log('onSize');}");


Senthilchettyin
2611 3 8
http://emrpms.blogspot.in...

Hi

I have one more question here. It is possible to show the empty record lines in the list if there are only fewer records in the list. Say for example
I have fixed height for the list box and from the DB, it shows the records and assume that we have only 3 records. So the remaining space will show as blank. Can
we show empty lines without much code ?

Regards
Senthil M

Neus
1415 14

Thank you jimmy!

jimmyshiau
4921 5
http://www.zkoss.org/

Hi Senthil,
Do you mean this feature?
http://books.zkoss.org/wiki/ZK_Component_Reference/Data/Listbox#Show_messages_when_empty

Senthilchettyin
2611 3 8
http://emrpms.blogspot.in...

No. Look at the picture. It shows only one record and also it shows empty records for better look and feel.

jimmyshiau
4921 5
http://www.zkoss.org/

You need to add empty data to the listModel, otherwise listbox/grid only render the data in the model.

[hide preview]