Take a look at the Take(int) and Skip(int) extension methods... For example, here's how to get the third page of results if we have 10 per page. (Note, you can also use Count() to make sure you have enough nodes before trying to generate this, and also to know whether you should really build that "Load More" button...)
How to load more elements - for-each
Hi Forum!
I have this code, and I want to only show 10 elements at first, and then a 'load more'-button should load the next 10 and so on.
How can I do that?
Best regards
Kim
@{
var root = Model.AncestorOrSelf();
var nodes = root.Descendants().Where("NodeTypeAlias == @0 and Visible", "Timestamp");
foreach (var node in nodes.OrderBy("timelineDate desc")){
<article class="twelve columns timelineElement element">
<div class="elementContent">
<a name="@node.Id"></a>
<span class="date">
@{
if (@node.timelineShortDate == true){
@node.timelineDate.ToString("yyyy")
}else {
@node.timelineDate.ToString("dd.MM.yyyy")
}
}
</span>
<h1><a href="@node.Url" title="@node.Name">@Html.Raw(node.pageTitle)</a></h1>
<p class="lead">@node.timelineTeaser</p>
<a href="@node.Url" title="@node.Name" class="readmore">► Læs mere</a>
@if (@node.HasValue("timelinePhoto")) {
dynamic mediaItems = @node.timelinePhoto.mediaItem;
<div class="elementImage">
<a href="@node.Url" title="@node.Name">
@if (mediaItems.Count() != 0)
{
foreach (var item in mediaItems)
{
var image = item.Image;
<img data-original="@image.umbracoFile" src="/css/images/lazy.gif" class="lazy" alt="@image.nodeName" />
<noscript><img src="@image.umbracoFile" /></noscript>
}
}
</a>
</div>
}
</div>
</article>
}
}
Hi Kim,
Take a look at the Take(int) and Skip(int) extension methods... For example, here's how to get the third page of results if we have 10 per page. (Note, you can also use Count() to make sure you have enough nodes before trying to generate this, and also to know whether you should really build that "Load More" button...)
foreach(varnode innodes.OrderBy("timelineDate desc").Take(10).Skip(20)) ...
Best of luck to you!
Whoops, sorry, had those backwards i think. You would likely want to skip before you took! Anyhow, good luck!
Hi Funka!
Thanks!
Okay, then I just have to figure out the next step - a way of building that button ... should I use some querystring reading?
Best regards!
@Kim were you able to resolve this as i am also facing the same requirements
is working on a reply...