开发者

datatable scroll

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜