mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #746 from phalkunz/7601-listview-sort-by-title
GridFieldSortableHeader now allows composite fields to be sorted based db fields (see #7601)
This commit is contained in:
commit
3946a3e991
@ -14,6 +14,9 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
|
|||||||
*/
|
*/
|
||||||
protected $throwExceptionOnBadDataType = true;
|
protected $throwExceptionOnBadDataType = true;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
public $fieldSorting = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine what happens when this component is used with a list that isn't {@link SS_Filterable}.
|
* Determine what happens when this component is used with a list that isn't {@link SS_Filterable}.
|
||||||
*
|
*
|
||||||
@ -49,6 +52,24 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify sortings with fieldname as the key, and actual fieldname to sort as value.
|
||||||
|
* Example: array("MyCustomTitle"=>"Title", "MyCustomBooleanField" => "ActualBooleanField")
|
||||||
|
*
|
||||||
|
* @param array $casting
|
||||||
|
*/
|
||||||
|
public function setFieldSorting($sorting) {
|
||||||
|
$this->fieldSorting = $sorting;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getFieldSorting() {
|
||||||
|
return $this->fieldSorting;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the header row providing titles with sort buttons
|
* Returns the header row providing titles with sort buttons
|
||||||
*/
|
*/
|
||||||
@ -65,6 +86,7 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
|
|||||||
$currentColumn++;
|
$currentColumn++;
|
||||||
$metadata = $gridField->getColumnMetadata($columnField);
|
$metadata = $gridField->getColumnMetadata($columnField);
|
||||||
$title = $metadata['title'];
|
$title = $metadata['title'];
|
||||||
|
if(isset($this->fieldSorting[$columnField]) && $this->fieldSorting[$columnField]) $columnField = $this->fieldSorting[$columnField];
|
||||||
if($title && $gridField->getList()->canSortBy($columnField)) {
|
if($title && $gridField->getList()->canSortBy($columnField)) {
|
||||||
$dir = 'asc';
|
$dir = 'asc';
|
||||||
if($state->SortColumn == $columnField && $state->SortDirection == 'asc') {
|
if($state->SortColumn == $columnField && $state->SortDirection == 'asc') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user