Skip to content
This repository
Browse code

GridFieldSortableHeader now allows composite fields to be sorted base…

…d db fields (see #7601)
  • Loading branch information...
commit e595b8fc75acfcab5ce918d60711b44de1224f38 1 parent abbce15
Saophalkun Ponlu authored August 28, 2012
22  forms/gridfield/GridFieldSortableHeader.php
@@ -13,6 +13,9 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
13 13
 	 * See {@link setThrowExceptionOnBadDataType()}
14 14
 	 */
15 15
 	protected $throwExceptionOnBadDataType = true;
  16
+
  17
+	/** @var array */
  18
+	public $fieldSorting = array();
16 19
 	
17 20
 	/**
18 21
 	 * 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) {
48 51
 			return false;
49 52
 		}
50 53
 	}
  54
+
  55
+	/**
  56
+	 * Specify sortings with fieldname as the key, and actual fieldname to sort as value.
  57
+	 * Example: array("MyCustomTitle"=>"Title", "MyCustomBooleanField" => "ActualBooleanField")
  58
+	 *
  59
+	 * @param array $casting
  60
+	 */
  61
+	public function setFieldSorting($sorting) {
  62
+		$this->fieldSorting = $sorting;
  63
+		return $this;
  64
+	}
  65
+	
  66
+	/**
  67
+	 * @return array
  68
+	 */
  69
+	public function getFieldSorting() {
  70
+		return $this->fieldSorting;
  71
+	}
51 72
 	
52 73
 	/**
53 74
 	 * Returns the header row providing titles with sort buttons 
@@ -65,6 +86,7 @@ public function getHTMLFragments($gridField) {
65 86
 			$currentColumn++;
66 87
 			$metadata = $gridField->getColumnMetadata($columnField);
67 88
 			$title = $metadata['title'];
  89
+			if(isset($this->fieldSorting[$columnField]) && $this->fieldSorting[$columnField]) $columnField = $this->fieldSorting[$columnField];
68 90
 			if($title && $gridField->getList()->canSortBy($columnField)) {
69 91
 				$dir = 'asc';
70 92
 				if($state->SortColumn == $columnField && $state->SortDirection == 'asc') {

0 notes on commit e595b8f

Please sign in to comment.
Something went wrong with that request. Please try again.