数据表滚动 [英] datatable scroll
问题描述
我有一个dataTable,如果记录超过,我正在使用scrollBar,让我们说20。问题是回发后div滚动条到顶部。无论如何我可以在回发后修复div的滚动重置。谢谢。
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 resetting of scroll of div after post back. Thanks.
推荐答案
您可以使用 element.scrollTop
。利用表单的 onsubmit
处理程序将其保存为隐藏的输入元素:
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" />
...
使用此功能
function saveScrollPos() {
var scrollPos = document.getElementById('divId').scrollTop;
document.getElementById('formId:scrollPos').value = scrollPos;
}
这种方式可用作请求参数,名称为 formId:scrollPos
。您可以在onload期间使用Javascript设置它:
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;
}
这里 divId
显然是你要滚动的< div>
的ID。
Here the divId
is obviously the ID of the <div>
you'd like to scroll.
这篇关于数据表滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!