From 8b7ee7dd47b1c60bb1e234e88f40346a1742506c Mon Sep 17 00:00:00 2001
From: Daniel Brown <ddb@star.sr.bham.ac.uk>
Date: Thu, 8 Aug 2013 14:24:36 +0100
Subject: [PATCH] adding proper numerical sorting to tables

---
 .../web/templates/finesse_kat_history.html    | 26 ++++++++++++--
 .../web/templates/finesse_test_view.html      | 35 +++++++++++++++++--
 2 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/pykat/testing/web/templates/finesse_kat_history.html b/pykat/testing/web/templates/finesse_kat_history.html
index cae7c67..5a59b61 100644
--- a/pykat/testing/web/templates/finesse_kat_history.html
+++ b/pykat/testing/web/templates/finesse_kat_history.html
@@ -34,9 +34,31 @@
     
     <script type="text/JavaScript">
         $(document).ready(function(){
+                    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
+                        "num-html-pre": function ( a ) {
+                            var x = String(a).replace( /<[\s\S]*?>/g, "" );
+                            return parseFloat( x );
+                        },
+                     
+                        "num-html-asc": function ( a, b ) {
+                            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
+                        },
+                     
+                        "num-html-desc": function ( a, b ) {
+                            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
+                        }
+                    } );
                     
-                    gtable = $('#tblHistory').dataTable();
-                    
+                    gtable = $('#tblHistory').dataTable({
+                        "iDisplayLength":250,
+                        "aoColumns": [
+                            { "sType": "num-html" },
+                            null,
+                            { "sType": "date" },
+                            { "sType": "numeric" },
+                            { "sType": "numeric" }
+                        ]
+                    } );
                 
             });
     </script>
diff --git a/pykat/testing/web/templates/finesse_test_view.html b/pykat/testing/web/templates/finesse_test_view.html
index ba69fd9..4330ba9 100644
--- a/pykat/testing/web/templates/finesse_test_view.html
+++ b/pykat/testing/web/templates/finesse_test_view.html
@@ -52,9 +52,40 @@
     <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
     
     <script type="text/JavaScript">
+        
+        
         $(document).ready(function(){
-                    
-                    gtable = $('#tblResults').dataTable();
+                    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
+                        "num-html-pre": function ( a ) {
+                            console.log("1");
+                            var x = String(a).replace( /<[\s\S]*?>/g, "" );
+                            return parseFloat( x );
+                        },
+                     
+                        "num-html-asc": function ( a, b ) {
+                        console.log("2");
+                            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
+                        },
+                     
+                        "num-html-desc": function ( a, b ) {
+                        console.log("3");
+                            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
+                        }
+                    } );
+                    gtable = $('#tblResults').dataTable({
+                        "iDisplayLength":250,
+                        "aLengthMenu": [[-1], ['All']],
+                        "aoColumns": [
+                            null,
+                            null,
+                            { "sType": "numeric" },
+                            {"bSearchable": false, "bSortable": false},
+                            {"bSearchable": false, "bSortable": false},
+                            {"bSearchable": false, "bSortable": false},
+                            {"bSearchable": false, "bSortable": false},
+                            {"bSearchable": false, "bSortable": false}
+                        ]
+                    } );
                     
                 
             });
-- 
GitLab