是否有ASP.net的虚拟列表视图?
我为asp.net找到的大多数表(以及网格、列表视图、数据表、数据网格、网格视图、列表网格)都期望用户对数据进行页面化。
例如,我想要一个包含10,000项的列表视图;我不想要10页。
1994年,使用“虚拟”模式的listview解决了长列表的问题。只需要给出要显示的项的数量。所需的有关这些项的控制信息(即用户将其滚动到视图中,或尝试对列进行排序)。
是否有人创建了虚拟列表视图(可能使用异步Javascript和XML,或者同步Javascript和XML)?
如果答案是“不是”:不要害怕回答这个问题。答案没有什么不对:
No.
发布于 2012-06-11 14:12:09
我只是做了一个虚拟的ListView示例。
我从呈现div的中继器开始,属性包含需要加载的数据库id。
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div data-id="<%# GetID(Container.DataItem) %>" class="DataLine">
loading...
</div>
</ItemTemplate>
</asp:Repeater>接下来,检查这个div是否可见的javascript,并使用ajax获取数据。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = elem.offset().top;
var elemBottom = elemTop + elem.height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
var cTimerID = null;
function RunWithSomeDelay()
{
if(cTimerID)
clearTimeout(cTimerID);
cTimerID = setTimeout(CheckWhatToShow, 1000);
}
function CheckWhatToShow()
{
$(".DataLine").each(function(i, selected) {
var ThisOne = $(selected);
if(ThisOne.attr("Done") != "1")
{
if(isScrolledIntoView(ThisOne))
{
ThisOne.attr("Done", "1");
// here you can use a simple ajax load, to load your data.
ThisOne.text(ThisOne.attr("data-id"));
}
}
});
}
$(document).ready(function() {
// first time run
CheckWhatToShow();
// run on scrool
$(window).scroll(RunWithSomeDelay);
});
</script>下面是我的测试代码
public partial class Dokimes_StackOverFlow_VirtualList : System.Web.UI.Page
{
List<int> oMainIds = new List<int>();
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 3000; i++)
oMainIds.Add(i);
Repeater1.DataSource = oMainIds;
Repeater1.DataBind();
}
public int GetID(object oItem){
return (int)oItem;
}
}我测试了它的工作发现。
下面是源代码:http://www.planethost.gr/VirtualList.rar
可做的改进:
更新我做了一些速度优化,并添加了ajax调用测试。对于这种优化工作,纠正包含数据的div的高度必须在整个页面中相同。左转加载一组数据,将其作为json获取并放置在正确的位置。
http://www.planethost.gr/VirtualList2.rar
发布于 2012-06-11 13:55:20
试着看看无限涡旋jQuery插件。我想这就像你在找什么。
https://stackoverflow.com/questions/10981084
复制相似问题