开发者

datatable scroll

开发者 https://www.devze.com 2022-12-25 21:54 出处:网络
I have a dataTable and I am using scrollBar if the records exceed ,lets say 20. The problem is after post back the div scroll bar goes to top. Is there anyway I can fix the开发者_如何学Python resettin

I have a dataTable and I am using scrollBar if the records exceed ,lets say 20. The problem is after post back the div scroll bar goes to top. Is there anyway I can fix the开发者_如何学Python resetting of scroll of div after post back. Thanks.


You can get and set the element's current scroll position in Javascript using element.scrollTop. Make use of the form's onsubmit handler to 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;
}

This way it's available as request parameter with the name formId:scrollPos. You can use Javascript to set it during onload:

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

Here the divId is obviously the ID of the <div> you'd like to scroll.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号