Dynamic scroll

I have a dataTable, and I use scrollBar if the records are greater than, say 20. The problem is that after sending back the scroll bar div goes to the top. In any case, I can fix resetting the scroll of the div after posting back. Thank.

+1
source share
1 answer

You can get and set the current scroll position of an element in Javascript using element.scrollTop. Use a form handler onsubmitto save it as a hidden input element:

<h:form id="formId" onsubmit="saveScrollPos()">
    <h:inputHidden id="scrollPos" />
    ...

with this function

function saveScrollPos() {
    var scrollPos = document.getElementById('divId').scrollTop;
    document.getElementById('formId:scrollPos').value = scrollPos;
}

Thus, it is available as a query parameter with a name formId:scrollPos. You can use Javascript to install it at boot time:

window.onload = function() {
    var scrollPos = <h:outputText value="#{param['formId:scrollPos']}" />;
    document.getElementById('divId').scrollTop = scrollPos;
}

divId - , , <div>, .

+2

All Articles