Skip to content

Commit

Permalink
GridFieldSortableHeader now allows composite fields to be sorted base…
Browse files Browse the repository at this point in the history
…d db fields (see #7601)
  • Loading branch information
phalkunz committed Aug 28, 2012
1 parent abbce15 commit e595b8f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions forms/gridfield/GridFieldSortableHeader.php
Expand Up @@ -13,6 +13,9 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
* See {@link setThrowExceptionOnBadDataType()}
*/
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}.
Expand Down Expand Up @@ -48,6 +51,24 @@ protected function checkDataType($dataList) {
return false;
}
}

/**
* 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
Expand All @@ -65,6 +86,7 @@ public function getHTMLFragments($gridField) {
$currentColumn++;
$metadata = $gridField->getColumnMetadata($columnField);
$title = $metadata['title'];
if(isset($this->fieldSorting[$columnField]) && $this->fieldSorting[$columnField]) $columnField = $this->fieldSorting[$columnField];
if($title && $gridField->getList()->canSortBy($columnField)) {
$dir = 'asc';
if($state->SortColumn == $columnField && $state->SortDirection == 'asc') {
Expand Down

0 comments on commit e595b8f

Please sign in to comment.