Bug 19509 - Database Tables in the Inspector should be sortable
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Jun 2010 03:23:38 +0000 (03:23 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Jun 2010 03:23:38 +0000 (03:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=19509

Reviewed by Darin Adler.

* inspector/front-end/StoragePanel.js:
(WebInspector.StoragePanel.prototype.dataGridForResult):
Make each column in the DataGrid sortable.
(WebInspector.StoragePanel.prototype._sortDataGrid.comparator):
Make sure to sort numeric columns by their numeric values, instead of lexicographically.
(WebInspector.StoragePanel.prototype._sortDataGrid):
Sort the entries in the DataGrid based on the selected column.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@61463 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/inspector/front-end/StoragePanel.js

index 0bbe8b0..35ce32d 100644 (file)
@@ -1,3 +1,18 @@
+2010-06-18  Jessie Berlin  <jberlin@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Bug 19509 - Database Tables in the Inspector should be sortable
+        https://bugs.webkit.org/show_bug.cgi?id=19509
+
+        * inspector/front-end/StoragePanel.js:
+        (WebInspector.StoragePanel.prototype.dataGridForResult):
+        Make each column in the DataGrid sortable.
+        (WebInspector.StoragePanel.prototype._sortDataGrid.comparator):
+        Make sure to sort numeric columns by their numeric values, instead of lexicographically.
+        (WebInspector.StoragePanel.prototype._sortDataGrid):
+        Sort the entries in the DataGrid based on the selected column.
+
 2010-06-18  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Oliver Hunt.
index ca1b276..fef7802 100644 (file)
@@ -289,6 +289,7 @@ WebInspector.StoragePanel.prototype = {
             var column = {};
             column.width = columnIdentifier.length;
             column.title = columnIdentifier;
+            column.sortable = true;
 
             columns[columnIdentifier] = column;
             ++numColumns;
@@ -313,9 +314,45 @@ WebInspector.StoragePanel.prototype = {
         for (var i = 0; i < length; ++i)
             dataGrid.appendChild(nodes[i]);
 
+        dataGrid.addEventListener("sorting changed", this._sortDataGrid.bind(this, dataGrid), this);
         return dataGrid;
     },
 
+    _sortDataGrid: function(dataGrid)
+    {
+        var nodes = dataGrid.children.slice();
+        var sortColumnIdentifier = dataGrid.sortColumnIdentifier;
+        var sortDirection = dataGrid.sortOrder === "ascending" ? 1 : -1;
+        var columnIsNumeric = true;
+
+        for (var i = 0; i < nodes.length; i++) {
+            if (isNaN(Number(nodes[i].data[sortColumnIdentifier])))
+                columnIsNumeric = false;
+        }
+
+        function comparator(dataGridNode1, dataGridNode2)
+        {
+            var item1 = dataGridNode1.data[sortColumnIdentifier];
+            var item2 = dataGridNode2.data[sortColumnIdentifier];
+
+            var comparison;
+            if (columnIsNumeric) {
+                // Sort numbers based on comparing their values rather than a lexicographical comparison.
+                var number1 = parseFloat(item1);
+                var number2 = parseFloat(item2);
+                comparison = number1 < number2 ? -1 : (number1 > number2 ? 1 : 0);
+            } else
+                comparison = item1 < item2 ? -1 : (item1 > item2 ? 1 : 0);
+
+            return sortDirection * comparison;
+        }
+
+        nodes.sort(comparator);
+        dataGrid.removeChildren();
+        for (var i = 0; i < nodes.length; i++)
+            dataGrid.appendChild(nodes[i]);
+    },
+
     updateDOMStorage: function(storageId)
     {
         var domStorage = this._domStorageForId(storageId);