Unverified 提交 cf11224f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1024 from katzyn/webconsole

Improve sorting in web console
......@@ -21,6 +21,10 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #1019: Console incorrectly sorts BigDecimal columns alphanumerically
</li>
<li>PR #1021: Update JdbcDatabaseMetaData to JDBC 4.1 (Java 7)
</li>
<li>Issue #992: 1.4.196+ client cannot use DatabaseMetaData with 1.4.195- server
</li>
<li>Issue #1016: ResultSet.getObject() should return enum value, not ordinal
......
......@@ -163,6 +163,10 @@ function getInnerText(el) {
return str;
}
function isNullCell(td) {
return td.childNodes.length == 1 && (td.childNodes[0].nodeName == "I");
}
function resortTable(link) {
// get the span
var span;
......@@ -175,26 +179,39 @@ function resortTable(link) {
var td = link.parentNode;
var column = td.cellIndex;
var table = getParent(td,'TABLE');
if (table.rows.length <= 1) return;
var rows = table.rows;
if (rows.length <= 1) return;
// detect sort type
var sortNumeric = false;
var x = getInnerText(table.rows[1].cells[column]);
if (x.match(/^[\d\.]+$/)) {
sortNumeric = true;
var sortNumeric = true;
for (i = 1; i < rows.length; i++) {
var td = rows[i].cells[column];
if (!isNullCell(td)) {
var x = getInnerText(td);
// H2 does not return numeric values with leading +, but may return
// values in scientific notation
if (!x.match(/^\-?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$/)) {
sortNumeric = false;
break;
}
}
}
var newRows = new Array();
var rows = table.rows;
for (i=1; i<rows.length; i++) {
var o = new Object();
o.data = rows[i];
o.id = i;
var td = o.data.cells[column];
var n = isNullCell(td);
o.isNull = n;
if (!n) {
var txt = getInnerText(td);
if (sortNumeric) {
o.sort = parseFloat(getInnerText(o.data.cells[column]));
o.sort = parseFloat(txt);
if (isNaN(o.sort)) o.sort = 0;
} else {
o.sort = getInnerText(o.data.cells[column]);
o.sort = txt;
}
}
newRows[i-1] = o;
}
......@@ -240,6 +257,10 @@ function getParent(el, pTagName) {
}
function sortCallback(ra, rb) {
if (ra.isNull) {
return rb.isNull ? (ra.id - rb.id) : -1;
} else if (rb.IsNull) {
return 1;
}
return (ra.sort==rb.sort) ? (ra.id-rb.id) : (ra.sort<rb.sort ? -1 : 1);
}
......@@ -771,4 +771,4 @@ openoffice organize libre systemtables gmane sea borders announced millennium al
opti excessively
iterators tech enums incompatibilities loses reimplement readme reorganize milli subdirectory linkplain inspections
geometries sourceschema destschema generatedcolumn
geometries sourceschema destschema generatedcolumn alphanumerically
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论