From ea48279a905ac4bcfdbf710d51ed39f086e930fe Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 23 Nov 2012 15:25:55 +0000 Subject: [PATCH] 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). SVN:trunk[2459] --- application/datatable.class.inc.php | 7 ++++--- application/nicewebpage.class.inc.php | 2 +- pages/ajax.render.php | 11 ++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/application/datatable.class.inc.php b/application/datatable.class.inc.php index 417b3bf20..8b7776794 100644 --- a/application/datatable.class.inc.php +++ b/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( <<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) diff --git a/application/nicewebpage.class.inc.php b/application/nicewebpage.class.inc.php index f51016ecc..77302bc19 100644 --- a/application/nicewebpage.class.inc.php +++ b/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'); diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 031fd1a5d..60e101593 100644 --- a/pages/ajax.render.php +++ b/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