Get KoolPHP UI with 30% OFF!

Sort by Custom Array

Hallie
Can anyone let me know why this is sorting alphabetically and not by the $month array? Any advice is greatly appreciated!
$month = array('08 Aug', '09 Sep', '10 Oct','11 Nov','12 Dec','01 Jan', '02 Feb','03 Mar',	'04 Apr',	'05 May','06 Jun','07 Jul');
	$field = new PivotField("month");
	$field->Text = "Mon";
	$field->Sort = "$month";
	$pivot->AddColumnField($field);
Posted Jun 8, 2017 , edited Jun 8, 2017 Kool
David
Hi Hallie,
To customize a field sorting, please use the following code:
  function Groups_Compare_custom($_group1, $_group2) {
    $times = array('08 Aug', '09 Sep', '10 Oct','11 Nov','12 Dec','01 Jan', '02 Feb','03 Mar', '04 Apr',	'05 May', '06 Jun', '07 Jul');
    $value1 = $_group1->GetSortValue();
    $value2 = $_group2->GetSortValue();
    $index1 = 0;
    $index2 = 0;
    foreach ($times as $i => $time) {
      if (strpos($value1, $time) !== false)
        $index1 = $i;
      if (strpos($value2, $time) !== false)
        $index2 = $i;
    }
    
    if ($index1 == $index2)
      return 0;
    if ($index1 < $index2)
      return -1;
    if ($index1 > $index2)
      return 1;
  }
  $field = new PivotField("Time");
  // $field->AllowSorting = false;
  $field->Sort = 'custom';
  $pivot->AddColumnField($field);

Please let us know if this solves your issue. Thanks!
Posted Jun 9, 2017 Kool
Hallie
I got this working!! Thank you
Posted Jun 9, 2017 , edited Jun 9, 2017 Kool