Changeset 61463 in webkit


Ignore:
Timestamp:
Jun 18, 2010 8:23:38 PM (14 years ago)
Author:
jberlin@webkit.org
Message:

Bug 19509 - Database Tables in the Inspector should be sortable
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.

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r61462 r61463  
     12010-06-18  Jessie Berlin  <jberlin@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Bug 19509 - Database Tables in the Inspector should be sortable
     6        https://bugs.webkit.org/show_bug.cgi?id=19509
     7
     8        * inspector/front-end/StoragePanel.js:
     9        (WebInspector.StoragePanel.prototype.dataGridForResult):
     10        Make each column in the DataGrid sortable.
     11        (WebInspector.StoragePanel.prototype._sortDataGrid.comparator):
     12        Make sure to sort numeric columns by their numeric values, instead of lexicographically.
     13        (WebInspector.StoragePanel.prototype._sortDataGrid):
     14        Sort the entries in the DataGrid based on the selected column.
     15
    1162010-06-18  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/WebCore/inspector/front-end/StoragePanel.js

    r54436 r61463  
    290290            column.width = columnIdentifier.length;
    291291            column.title = columnIdentifier;
     292            column.sortable = true;
    292293
    293294            columns[columnIdentifier] = column;
     
    314315            dataGrid.appendChild(nodes[i]);
    315316
     317        dataGrid.addEventListener("sorting changed", this._sortDataGrid.bind(this, dataGrid), this);
    316318        return dataGrid;
     319    },
     320
     321    _sortDataGrid: function(dataGrid)
     322    {
     323        var nodes = dataGrid.children.slice();
     324        var sortColumnIdentifier = dataGrid.sortColumnIdentifier;
     325        var sortDirection = dataGrid.sortOrder === "ascending" ? 1 : -1;
     326        var columnIsNumeric = true;
     327
     328        for (var i = 0; i < nodes.length; i++) {
     329            if (isNaN(Number(nodes[i].data[sortColumnIdentifier])))
     330                columnIsNumeric = false;
     331        }
     332
     333        function comparator(dataGridNode1, dataGridNode2)
     334        {
     335            var item1 = dataGridNode1.data[sortColumnIdentifier];
     336            var item2 = dataGridNode2.data[sortColumnIdentifier];
     337
     338            var comparison;
     339            if (columnIsNumeric) {
     340                // Sort numbers based on comparing their values rather than a lexicographical comparison.
     341                var number1 = parseFloat(item1);
     342                var number2 = parseFloat(item2);
     343                comparison = number1 < number2 ? -1 : (number1 > number2 ? 1 : 0);
     344            } else
     345                comparison = item1 < item2 ? -1 : (item1 > item2 ? 1 : 0);
     346
     347            return sortDirection * comparison;
     348        }
     349
     350        nodes.sort(comparator);
     351        dataGrid.removeChildren();
     352        for (var i = 0; i < nodes.length; i++)
     353            dataGrid.appendChild(nodes[i]);
    317354    },
    318355
Note: See TracChangeset for help on using the changeset viewer.