Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GridFieldSortableHeader now allows composite fields to be sorted base…

…d db fields (see #7601)
  • Loading branch information...
commit e595b8fc75acfcab5ce918d60711b44de1224f38 1 parent abbce15
@phalkunz phalkunz authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 forms/gridfield/GridFieldSortableHeader.php
View
22 forms/gridfield/GridFieldSortableHeader.php
@@ -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}.
@@ -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
@@ -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') {
Please sign in to comment.
Something went wrong with that request. Please try again.