Revision: 3840
http://vexi.svn.sourceforge.net/vexi/?rev=3840&view=rev
Author: jeffbuhrt
Date: 2010-05-20 01:10:59 +0000 (Thu, 20 May 2010)
Log Message:
-----------
Fixes sort of basic table. Sort was random because it just sorted nulls. The
compare function now uses .text for a string and .value for a number (like it
was before). [Try the demo to see that it now works.]
Modified Paths:
--------------
trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/body.t
Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/body.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/body.t
2010-05-12 02:12:45 UTC (rev 3839)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/body.t
2010-05-20 01:10:59 UTC (rev 3840)
@@ -122,10 +122,10 @@
}
/** compares two strings */
- var compString = function(a, b) { return (a?a.toLowerCase():null) >
(b?b.toLowerCase():null); }
+ var compString = function(a, b) { return (a.text ?
a.text.toLowerCase():null) > (b.text ? b.text.toLowerCase():null); }
/** compares two numbers */
- var compNumber = function(a, b) { return a > b; }
+ var compNumber = function(a, b) { return a.value > b.value; }
/** sort items in ascending order according to column index 'ind' */
thisbox.sortAscending = function(ind, datatype) {
@@ -135,14 +135,14 @@
vexi.log.info("sorting: "+ind+", "+datatype+", "+n);
}
// robustly select comparison function
- var comp = (datatype == "string") ? compString : compNumber;
+ var comp = (datatype != "number") ? compString : compNumber;
// iterate through children
for (var i=1; n > i; i++) {
- if (comp(thisbox[i][ind].value, thisbox[i-1][ind].value)) {
+ if (comp(thisbox[i][ind], thisbox[i-1][ind])) {
// [v0, ..., v[i-1], v[i] - keep current order
continue;
}
- if (comp(thisbox[0][ind].value, thisbox[i][ind].value)) {
+ if (comp(thisbox[0][ind], thisbox[i][ind])) {
// [vi, v0, ...] - goes at the start of the list
thisbox[0] = thisbox[i];
continue;
@@ -154,10 +154,10 @@
// binary search (?)
do {
- if (comp(thisbox[i][ind].value, thisbox[mid][ind].value)) {
+ if (comp(thisbox[i][ind], thisbox[mid][ind])) {
// [..., vm, ..., vi, ..., vh, ...] - above mid
lo = mid;
- } else if (comp(thisbox[mid][ind].value,
thisbox[i][ind].value)) {
+ } else if (comp(thisbox[mid][ind], thisbox[i][ind])) {
// [..., vl, ..., vi, ..., vm, ...] - below mid
hi = mid;
} else {
@@ -188,14 +188,14 @@
vexi.log.info("sorting: "+ind+", "+datatype+", "+n);
}
// robustly select comparison function
- var comp = (datatype == "string") ? compString : compNumber;
+ var comp = (datatype != "number") ? compString : compNumber;
// iterate through children
for (var i=1; n>i; i++) {
- if (comp(thisbox[i-1][ind].value, thisbox[i][ind].value)) {
+ if (comp(thisbox[i-1][ind], thisbox[i][ind])) {
// [v0, ..., v[i-1], v[i] - keep current order
continue;
}
- if (comp(thisbox[i][ind].value, thisbox[0][ind].value)) {
+ if (comp(thisbox[i][ind], thisbox[0][ind])) {
// [vi, v0, ...] - goes at the start of the list
thisbox[0] = thisbox[i];
continue;
@@ -207,10 +207,10 @@
// binary search (?)
do {
- if (comp(thisbox[mid][ind].value, thisbox[i][ind].value)) {
+ if (comp(thisbox[mid][ind], thisbox[i][ind])) {
// [..., vm, ..., vi, ..., vh, ...] - above mid
lo = mid;
- } else if (comp(thisbox[i][ind].value,
thisbox[mid][ind].value)) {
+ } else if (comp(thisbox[i][ind], thisbox[mid][ind])) {
// [..., vl, ..., vi, ..., vm, ...] - below mid
hi = mid;
} else {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn