提交 f82b4b69 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix order of NULL values in web console sort

上级 ba15559f
...@@ -163,6 +163,10 @@ function getInnerText(el) { ...@@ -163,6 +163,10 @@ function getInnerText(el) {
return str; return str;
} }
function isNullCell(td) {
return td.childNodes.length == 1 && (td.childNodes[0].nodeName == "I");
}
function resortTable(link) { function resortTable(link) {
// get the span // get the span
var span; var span;
...@@ -175,26 +179,31 @@ function resortTable(link) { ...@@ -175,26 +179,31 @@ function resortTable(link) {
var td = link.parentNode; var td = link.parentNode;
var column = td.cellIndex; var column = td.cellIndex;
var table = getParent(td,'TABLE'); var table = getParent(td,'TABLE');
var rows = table.rows;
if (table.rows.length <= 1) return; if (rows.length <= 1) return;
// detect sort type // detect sort type
var sortNumeric = false; var sortNumeric = false;
var x = getInnerText(table.rows[1].cells[column]); var x = getInnerText(rows[1].cells[column]);
if (x.match(/^[\d\.]+$/)) { if (x.match(/^[\d\.]+$/)) {
sortNumeric = true; sortNumeric = true;
} }
var newRows = new Array(); var newRows = new Array();
var rows = table.rows;
for (i=1; i<rows.length; i++) { for (i=1; i<rows.length; i++) {
var o = new Object(); var o = new Object();
o.data = rows[i]; o.data = rows[i];
o.id = i; o.id = i;
if (sortNumeric) { var td = o.data.cells[column];
o.sort = parseFloat(getInnerText(o.data.cells[column])); var n = isNullCell(td);
if (isNaN(o.sort)) o.sort = 0; o.isNull = n;
} else { if (!n) {
o.sort = getInnerText(o.data.cells[column]); var txt = getInnerText(td);
if (sortNumeric) {
o.sort = parseFloat(txt);
if (isNaN(o.sort)) o.sort = 0;
} else {
o.sort = txt;
}
} }
newRows[i-1] = o; newRows[i-1] = o;
} }
...@@ -240,6 +249,10 @@ function getParent(el, pTagName) { ...@@ -240,6 +249,10 @@ function getParent(el, pTagName) {
} }
function sortCallback(ra, rb) { 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); return (ra.sort==rb.sort) ? (ra.id-rb.id) : (ra.sort<rb.sort ? -1 : 1);
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论