A front-end control to make sorting SilverStripe lists easy
PHP Scheme
Latest commit 545356e Feb 17, 2016 @wilr wilr Merge pull request #11 from helpfulrobot/add-standard-scrutinizer-config
Added standard Scrutinizer config
Permalink
Failed to load latest commit information.
code
templates/Includes FIX: pass $this back from ListSorter_Option->setID to allow chaining. Aug 29, 2014
tests
.editorconfig Added standard .editorconfig file Dec 31, 2015
.gitattributes
.scrutinizer.yml Added standard Scrutinizer config Feb 16, 2016
.travis.yml
CHANGELOG.md Added unit tests, updated docs Aug 28, 2014
CONTRIBUTING.md
README.md
_config.php first comit Sep 3, 2013
composer.json
phpunit.xml.dist

README.md

SilverStripe List Sorter

A front-end control for sorting SilverStripe lists easily. The aim of this module is to make sorting lists as simple as it is to use PaginatedList.

Requirements

  • SilverStripe 3+

Usage

There are a few ways you can define sort options within an array.

Make a public function on your controller:

function getSorter(){
    $sorts = array(
        'Title', //DB field name only
        'Popularity' => 'Popularity DESC', //map title to sort sql
        'Price' => array("BasePrice" => "ASC"), //map title to data list sort
        new ListSorter_Option("Age", "Created DESC", //object
            new ListSorter_Option("Age", array("Created" => "ASC")) //reverse
        )
    );
    return new ListSorter($this->request,$sorts);
}

Call that function when updating your list:

public function getSortableChildren() {
    $list = $this->Children();
    $list = $this->getSorter()->sortList($list);
    return $list;
}

Use my template or roll your own.

<% include Sorter %>
<ul>
<% loop SortableChildren %>
    <li>$Title</li>
<% end_loop %>
</ul>