Pārlūkot izejas kodu

Bug fix:
- Correct intial sort order of a table if the default sort column is not an "alphabetical" column (i.e. IP Address)
- Properly sort on the first column (name) when the name is made of a column with a different sort algorithm (i.e. IP Address).

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2459 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 12 gadi atpakaļ
vecāks
revīzija
fb547fac0c

+ 4 - 3
application/datatable.class.inc.php

@@ -506,16 +506,17 @@ EOF;
 				$aDefaultSort[] = "[".($iColOffset).",".($bAscending ? '0' : '1')."]";
 			}
 		}
-		$sSortList = '';
+		$sFakeSortList = '';
 		if (count($aDefaultSort) > 0)
 		{
-			$sSortList = ', sortList: ['.implode(',', $aDefaultSort).']';
+			$sFakeSortList = '['.implode(',', $aDefaultSort).']';
 		}
 		$sOQL = addslashes($this->oSet->GetFilter()->serialize());
 		$oPage->add_ready_script(
 <<<EOF
 var oTable = $('#{$this->iListId} table.listResults');
-oTable.tablesorter( { $sHeaders widgets: ['myZebra', 'truncatedList'] $sSortList} ).tablesorterPager({container: $('#pager{$this->iListId}'), totalRows:$iCount, size: $iPageSize, filter: '$sOQL', extra_params: '$sExtraParams', select_mode: '$sSelectModeJS', displayKey: $sDisplayKey, columns: $sJSColumns, class_aliases: $sJSClassAliases $sCssCount});
+oTable.tablesorter( { $sHeaders widgets: ['myZebra', 'truncatedList']} ).tablesorterPager({container: $('#pager{$this->iListId}'), totalRows:$iCount, size: $iPageSize, filter: '$sOQL', extra_params: '$sExtraParams', select_mode: '$sSelectModeJS', displayKey: $sDisplayKey, columns: $sJSColumns, class_aliases: $sJSClassAliases $sCssCount});
+oTable.trigger("fakesorton", [$sFakeSortList]);
 EOF
 		);
 		//if ($iNbPages == 1)

+ 1 - 1
application/nicewebpage.class.inc.php

@@ -42,7 +42,7 @@ class NiceWebPage extends WebPage
 		$this->add_linked_script('../js/jquery-ui-1.8.17.custom.min.js');
 		$this->add_linked_script("../js/hovertip.js");
 		// table sorting
-		$this->add_linked_script("../js/jquery.tablesorter.min.js");
+		$this->add_linked_script("../js/jquery.tablesorter.js");
 		$this->add_linked_script("../js/jquery.tablesorter.pager.js");
 		$this->add_linked_script("../js/jquery.tablehover.js");
 		$this->add_linked_script('../js/field_sorter.js');

+ 10 - 1
pages/ajax.render.php

@@ -105,7 +105,16 @@ try
 					{
 						if ($iSortCol == $iSortIndex)
 						{
-							$aOrderBy['friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
+							$aNameSpec = MetaModel::GetNameSpec($oFilter->GetClass());
+							if ($aNameSpec[0] == '%1$s')
+							{
+								// The name is made of a single column, let's sort according to the sort algorithm for this column
+								$aOrderBy[$aNameSpec[1][0]] = (utils::ReadParam('sort_order', 'asc') == 'asc');
+							}
+							else
+							{
+								$aOrderBy['friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
+							}
 						}
 					}
 					else