Jump to:

23545 Posts in 19310 Topics by 2888 members

General Questions

SilverStripe Forums » General Questions » [RESOLVED] dataobjectset paginating search results

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

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

Page: 1
Go to End
Author Topic: 946 Views
  • gregsaunders
    Community Member
    12 Posts

    [RESOLVED] dataobjectset paginating search results Link to this post

    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 %>

  • gregsaunders
    Community Member
    12 Posts

    Re: [RESOLVED] dataobjectset paginating search results Link to this post

    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.


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.