Переглянути джерело

Fixed Trac #628: sort order and configurable tables

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2523 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 роки тому
батько
коміт
3db1c285ae
3 змінених файлів з 39 додано та 6 видалено
  1. 1 1
      application/user.preferences.class.inc.php
  2. 22 1
      js/datatable.js
  3. 16 4
      pages/ajax.render.php

+ 1 - 1
application/user.preferences.class.inc.php

@@ -103,7 +103,7 @@ class appUserPreferences extends DBObject
 		}
 		else
 		{
-			unset($aPrefs[$sCode]);
+			unset($aPrefs[$sCodeOrPattern]);
 			self::$oUserPrefs->Set('preferences', $aPrefs);
 		}
 		// Save only if needed

+ 22 - 1
js/datatable.js

@@ -117,7 +117,28 @@ $(function()
 			oParams.defaults = bSaveAsDefaults;
 			oParams.class_aliases = this.options.oClassAliases;
 			oParams.columns = this.options.oColumns;
-			
+			var iSortCol = 0;
+			var sSortOrder = '';
+			for(var i in this.options.oColumns)
+			{
+				if (this.options.oColumns[i].checked)
+				{
+					if (this.options.oColumns[i].sort != 'none')
+					{
+						sSortOrder = this.options.oColumns[i].sort;
+					}
+					else
+					{
+						iSortCol++;
+					}
+				}
+			}
+			if ((this.options.sSelectMode != '') && (this.options.sSelectMode != 'none'))
+			{
+				iSortCol++;
+			}
+			oParams.sort_col = iSortCol;
+			oParams.sort_order = sSortOrder;
 			var me = this;
 			$.post(this.options.sRenderUrl, oParams, function(data) {
 				// Do nothing...

+ 16 - 4
pages/ajax.render.php

@@ -82,6 +82,11 @@ try
 		$iEnd = utils::ReadParam('end',1);
 		$iSortCol = utils::ReadParam('sort_col','null');
 		$sSelectMode = utils::ReadParam('select_mode', '');
+		if (!empty($sSelectMode) && ($sSelectMode != 'none'))
+		{
+			// The first column is used for the selection (radio / checkbox) and is not sortable
+			$iSortCol--;
+		}
 		$bDisplayKey = utils::ReadParam('display_key', 'true') == 'true';
 		$aColumns = utils::ReadParam('columns', array(), false, 'raw_data');
 		$aClassAliases = utils::ReadParam('class_aliases', array());
@@ -105,11 +110,18 @@ try
 					{
 						if ($iSortCol == $iSortIndex)
 						{
-							$aNameSpec = MetaModel::GetNameSpec($oFilter->GetClass());
-							if ($aNameSpec[0] == '%1$s')
+							if (!MetaModel::HasChildrenClasses($oFilter->GetClass()))
 							{
-								// 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');
+								$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
 							{