Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[RESOLVED] dataobjectset paginating search results

Go to End

2 Posts   1407 Views


Community Member, 12 Posts

8 June 2011 at 3:24pm

Hi all! Can someone point me to a tutorial or an article on how to put together a search page that returns results requiring pagination; i.e. 10 results per page. I'm having a challenge getting the pagination thing to work. I have a functioning search form, controller that performs the search, returns the results to the record set display template but I get all the matching records in $Results and not just the first 10 (as an example).


here is the controller function ...

class ListingResidentialSearchPage_Controller extends Page_Controller {


	function doSubmitSearch($data, $form) {
		$area 			= $data['Area'];
		$price_from 	= $data['PriceFrom'];
		$price_to 		= $data['PriceTo'];
		$property_class = $data['PropertyClass'];
		$bedrooms 		= $data['Bedrooms'];
		$bathrooms 		= $data['Bathrooms'];
		$query			= "Area: $area, List Price Between $price_from and $price_to, Property Class: $property_class, Bedrooms: $bedrooms, Bathrooms: $bathrooms";
		$listings = DataObject::get(
			"Area = '$area' AND L_Price >= '$price_from' AND L_Price <= '$price_to' AND PClass = ($property_class) AND TBD $bedrooms AND FB $bathrooms",
			'L_Price asc',
		$data = array(
			'Results' => $listings,
			'Query'   => $query,
			'Title'   => 'Residential Search Results'
		return $this->customise($data)->renderWith(array('ListingResidentialSearchPage_results', 'Page'));

and here is the template ...

<div id="content_main" class="grid_9 content_main" style="padding-bottom: 10px;">
	<% if Level(2) %>
		<% include BreadCrumbs %>
	<% end_if %>

	<div class="typography">

		<h2>$Title: $Results.totalSize</h2>

		<p>You searched for: $Query</p>
		<% if Results %>
			<% control Results %>
				<div class="listing_record_summary" onclick="location.href='/listings/residential/view/$MLS_Number';" style="padding: 10px; margin-bottom: 10px; border: solid 1px grey;">
					<div style="width: 170px; float: left;">
						<img width="150px" src="$getListingImageMain.Url"/>
					<div style="width: 500px; float: left;">
						<h5>$Address, $Area || $$getListPriceMoneyFmt</h5>
						<p>Bedrooms: $TBD, Bathrooms: $FB || MLS&reg; $MLS_Number</p>
						<p>$getPublicRemarksSummary ...</p>
					<div style="clear:both;"></div>
			<% end_control %>
		<% else %>
			<p>Sorry, your search query did not return any results.</p>
		<% end_if %>

		<% if Results.MoreThanOnePage %>
			<div id="PageNumbers">
				<% if Results.NotLastPage %>
				<a class="next" href="$Results.NextLink" title="View the next page">Next</a>
				<% end_if %>
				<% if Results.NotFirstPage %>
				<a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
				<% end_if %>
					<% control Results.Pages %>
						<% if CurrentBool %>
						<% else %>
						<a href="$Link" title="View page number $PageNum">$PageNum</a>
						<% end_if %>
					<% end_control %>
				<p>Page $Results.CurrentPage of $Results.TotalPages</p>
		<% end_if %>


Community Member, 12 Posts

9 June 2011 at 4:26am

Edited: 09/06/2011 4:28am

Solved this one on my own. Two problems: I was returning the entire dataobjectset instead of using the


method of the dataobjectset and the other problem was not changing the action method of the form to GET from POST


This makes the page link URLs pass the search parameters back into the controller.

Refer to
... that's where I found the answer. Thanks sparkalow.