WebHierarchicalDataGrid: get_scrollTop() returns incorrect value

Infragistics WebHierarchicalDataGrid has a neat client-side built-in function get_scrollTop() – it is used if at any point you need to retrieve current vertical scroll position of the grid (e.g. to use it in your own calculations to display something at a specific position on the grid – tooltip, help, additional info etc.)

Unfortunately the function has a bug: its value only set if user actually manually scrolls the grid: using mouse and scrollbar on the right, keyboard etc. If no scrolling user-interaction is involved and scroll position changes due to other means (e.g. displayed data size changes) – the function retains original value, throwing all your calculation out of whack.

Case in point: Consider for example paging in child bands:

Let’s say a child grid has 2 rows on page 1 and only 1 row on page 2. When you click on page 2 – grid scroll position changes due to change in displayed number of rows. But if you check the value, returned by $find("myGrid").get_scrollTop() – surprise – it returns the same value you had seen on page 1.

But there’s a workaround. Take a look at the scrollbar on the right. Detailed examination will show that it’s actually a separate DIV container. No matter what caused grid scroll position to change – this DIV’s DOM .scrollTop property will always be current. And you have access to this DIV via $find("myGrid")._elements.vScrBar property.

So if instead of

var iScrollPos = $find("myGrid").get_scrollTop()

You use

var iScrollPos = $find("myGrid")._elements.vScrBar.scrollTop

You will always get accurate vertical scroll position.

Leave a Reply

Your email address will not be published. Required fields are marked *