[BUGFIX] EM: sorting in dataTable incorrect 74/19674/4
authorWouter Wolters <typo3@wouterwolters.nl>
Sat, 6 Apr 2013 13:22:53 +0000 (15:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 6 Apr 2013 17:35:50 +0000 (19:35 +0200)
The dataTable sortes version string incorrectly:

1.12.1
1.1.1

Intended:
1, 2, 3, ., 9, 10, 11, ., 99, 100, 101, ...

Also disable sorting on column "Actions"
Fixes: #46977
Releases: 6.1, 6.0

Change-Id: Ie6211edee52bf712f4463a57d800f0c1e705f1da
Reviewed-on: https://review.typo3.org/19674
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extensionmanager/Resources/Public/JavaScript/main.js
typo3/sysext/extensionmanager/Resources/Public/JavaScript/ter.js

index 07fbd83..0258528 100644 (file)
                        "bLengthChange":false,
                        'iDisplayLength':15,
                        "bStateSave":true,
-                       "fnDrawCallback": bindActions
+                       "fnDrawCallback": bindActions,
+                       'aoColumns': [
+                               null,
+                               null,
+                               null,
+                               null,
+                               { 'sType': 'version' },
+                               { 'bSortable': false },
+                               null
+                       ]
                });
 
                var getVars = getUrlVars();
                }
        }
 
+       $.fn.dataTableExt.oSort['version-asc'] = function(a, b) {
+               var result = compare(a,b);
+               result = result * -1;
+               return result;
+       };
+
+       $.fn.dataTableExt.oSort['version-desc'] = function(a, b) {
+               var result = compare(a,b);
+               return result;
+       };
+
+       function compare(a, b) {
+               if (a === b) {
+                       return 0;
+               }
+
+               var a_components = a.split(".");
+               var b_components = b.split(".");
+
+               var len = Math.min(a_components.length, b_components.length);
+
+               // loop while the components are equal
+               for (var i = 0; i < len; i++) {
+                       // A bigger than B
+                       if (parseInt(a_components[i]) > parseInt(b_components[i])) {
+                               return 1;
+                       }
+
+                       // B bigger than A
+                       if (parseInt(a_components[i]) < parseInt(b_components[i])) {
+                               return -1;
+                       }
+               }
+
+               // If one's a prefix of the other, the longer one is greater.
+               if (a_components.length > b_components.length) {
+                       return 1;
+               }
+
+               if (a_components.length < b_components.length) {
+                       return -1;
+               }
+               // Otherwise they are the same.
+               return 0;
+       }
+
        function bindActions() {
                $('.removeExtension').not('.transformed').each(function() {
                        $(this).data('href', $(this).attr('href'));
index 3eb40c2..92658c0 100644 (file)
                        "bInfo":false,
                        "bPaginate":false,
                        "bFilter":false,
-                       "bSort": false,
-                       "fnDrawCallback":bindDownload
+                       "fnDrawCallback":bindDownload,
+                       'aoColumns': [
+                               { 'bSortable': false },
+                               null,
+                               { 'sType': 'version' },
+                               null,
+                               null,
+                               null
+                       ]
                });
 
                $('#terSearchTable').dataTable({