Hi, I have quite a heavy homepage with a lot of children dataset that are also displayed with data and images.
Would it be possible to extend Silverstripe to fetch the children only via jQuery AJAX?
Thanks ben
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hi, I have quite a heavy homepage with a lot of children dataset that are also displayed with data and images.
Would it be possible to extend Silverstripe to fetch the children only via jQuery AJAX?
Thanks ben
I am trying to do something similar to this myself, but finding it difficult to find resources online for this topic!
I have set up a News Holder Page and a News Page. But I want to populate the holder via Ajax rather than loading everything at once, probably triggered when the browser is scrolled down down beyond currently loaded news.
I have a function in my controller which can return a specified amount of news teasers.
But I guess what I really need is for some way to tell my function that I already have X amount of data displayed on the page and I need you to continue loading from this point!
Does that make sense?
Has anybody done anything similar to this? Any assistance would be very appreciated.
Thanks Jay
On further investigation I have discovered the PaginatedList class, this may help me I think!
I think I am getting closer! But for some reason the $results will not render to my template! Can anyone help?
public function LatestNews(SS_HTTPRequest $request) {
if ((!isset($request)) || (!$request->requestVars())) {
$length = 2;
$current = 1;
} else {
$length = $request->getVar('length');
$current = $request->getVar('current');
}
$holder = ArticleHolder::get()->First();
$results = new PaginatedList(ArticlePage::get()->filter('ParentID', $holder->ID)->sort('Date DESC'));
$results->setPageLength($length);
$results->setCurrentPage($current);
return $results->renderWith('ArticleHolder');
}
You're calling renderWith on the Paginated list directly which works but you would need to use loop $Me to refer to the current object in scope. You also won't get any other variables from the current controller. A potential 'better' way is calling renderWith on the controller.
return $this->customise(new ArrayData(array(
'Results' => $results
))->renderWith('ArticleHolder');
Then you can use
<ul>
<% loop $Results %>
<li><a href="$Link">$Title</a></li>
<% end_loop %>
</ul>
Thanks for the reply, after much reading today I think I finally got there earlier.
I did this in the end:
public function LatestNews(SS_HTTPRequest $request) {
if (!isset($request->requestVars)) {
$length = 1;
$current = 1;
} else {
$length = $request->getVar('length');
$current = $request->getVar('current');
}
$holder = ArticleHolder::get()->First();
$results = new PaginatedList(ArticlePage::get()->filter('ParentID', $holder->ID)->sort('Date DESC'));
$results->setPageLength($length);
$results->setCurrentPage($current);
return $results->customise(array('LatestNews' => $results))->renderWith('newsteaser');
}
It seems to be working at the moment!
Thanks again.