PHPackages                             burnbright/silverstripe-listsorter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. burnbright/silverstripe-listsorter

Abandoned → [silvershop/silverstripe-listsorter](/?search=silvershop%2Fsilverstripe-listsorter)Silverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

burnbright/silverstripe-listsorter
==================================

Easily provide front-end sorting controls for SilverStripe lists

3.0.0(2y ago)1626.4k10[1 issues](https://github.com/silvershop/silverstripe-listsorter/issues)2BSD-3-ClausePHPCI failing

Since Jan 30Pushed 3d ago5 watchersCompare

[ Source](https://github.com/silvershop/silverstripe-listsorter)[ Packagist](https://packagist.org/packages/burnbright/silverstripe-listsorter)[ RSS](/packages/burnbright-silverstripe-listsorter/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (3)Versions (9)Used By (2)

SilverStripe List Sorter
========================

[](#silverstripe-list-sorter)

[![CI](https://github.com/silvershop/silverstripe-listsorter/actions/workflows/ci.yml/badge.svg)](https://github.com/silvershop/silverstripe-listsorter/actions/workflows/ci.yml)[![Version](https://camo.githubusercontent.com/417a68deeabaff329c37b9310c916f0fb9d13166141a745e4e21d3a8bdfefdb9/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696c7665727374726970652f73686172656472616674636f6e74656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/silvershop/silverstripe-listsorter)[![License](https://camo.githubusercontent.com/de85f40eca0bf834383f4c1e43745a7cce35f6c46d1db3393f77c763263be085/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73696c7665727374726970652f73686172656472616674636f6e74656e742e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

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

[](#requirements)

- SilverStripe ^6

Installation
------------

[](#installation)

```
composer require silvershop/silverstripe-listsorter
```

Usage
-----

[](#usage)

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

Make a public function on your controller:

```
public function getSorter(){
	$sorts = [
		'Title', //DB field name only
		'Popularity' => 'Popularity DESC', //map title to sort sql
		'Price' => ['BasePrice' => 'ASC'], //map title to data list sort
		ListSorterOption::create('Age', ['Created' => 'DESC']), //object
		ListSorterOption::create('Age', ['Created' => 'ASC']) //reverse
    ];

	return ListSorter::create($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.

```

	$Title

```

Usage with Silvershop
---------------------

[](#usage-with-silvershop)

Silvershop's PageCategoryController comes with some sortings predefined. If you want to define your own sorting possibilities, you can add an Extension to ProductCategory like this:

```
