Sorry for this: here is the diff without CR/LF:
Sebastian Werner schrieb:
Dietrich Streifert schrieb:
Here It is and SOLVED:
Please have a look at the List_4.html example attached to the mail.
The trick is to NOT sort the children array. A new array is built
upon the sort criteria (eg. the label or the value of the item) which
holds a reference to the child item.
Just my 2 cents:
It was a really bad idea to sort the array which is accessed through a
getter. As javascript always references to this array, also if you
modify it, you will override many qooxdoo internals (and probably
broke them) this way.
Then this new array is sorted and after that the items are re-added
in the new order by callint the addAtEnd method of the QxList.
addAtEnd is IMHO a bit complex. Normally you does not need to re-add
them (ok, qooxdoo does not really will re-add them, as it compares the
old and new parent before), but there is currently unfortunately no
other way to solve this. I hope the overhead is not to big.
addAtEnd is a bit to complex because it always need the current
length. Normally you will use a loop to refill the children to the
parent. Possible you can alternativly does something like this:
for (var i=0, a=sortedChildren, l=a.length; i<l; i++) {
myParent.addAt(a[i], i);
};
This should be a small time faster. If we need something like this
sorting more often we should thought about a more optimized way to
refresh such widgets.
Sebastian
I created three new methods for QxList:
1) internal _sortItemsCompare method for sorting comparison
2) sortItemsByString() which sorts asc/desc by the getLabel() value
3) sortItemsByValue() which sorts asc/desc by the getValue() value
Should I put the new methods into QxList and create a patch for QxList?
------------------------------------------------------------------------
QxList Item Sorting demo
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
--
Mit freundlichen Grüßen
Dietrich Streifert
Visionet GmbH
--- source/script/widgets/QxList.js.orig 2005-11-28 11:31:22.197065000
+0100
+++ source/script/widgets/QxList.js 2005-11-28 11:52:11.765382000 +0100
@@ -303,3 +303,51 @@
proto.findValueExact = function(vText, vStartIndex) {
return this._findItem(vText, vStartIndex || 0, "ValueExact");
};
+
+/*
+
-------------------------------------------------------------------------------
+ SORT SUPPORT
+
-------------------------------------------------------------------------------
+*/
+
+proto._sortItemsCompare = function(a,b) {
+ var ret = a.key < b.key ? -1 : ( a.key == b.key ? 0 : 1 );
+ return ret;
+};
+
+proto.sortItemsByString = function(reverse) {
+ var sortitems = [];
+ var items = this.getChildren();
+
+ for(var i=0;i<items.length;i++) {
+ sortitems[i] = { key:items[i].getLabel(), item:items[i] };
+ }
+
+ sortitems.sort(this._sortItemsCompare);
+ if ( reverse ) {
+ sortitems.reverse();
+ }
+
+ for(var i=0;i<sortitems.length;i++) {
+ this.addAt(sortitems[i].item,i);
+ }
+};
+
+proto.sortItemsByValue = function(reverse) {
+ var sortitems = [];
+ var items = this.getChildren();
+
+ for(var i=0;i<items.length;i++) {
+ sortitems[i] = { key:items[i].getValue(), item:items[i] };
+ }
+
+ sortitems.sort(this._sortItemsCompare);
+ if ( reverse ) {
+ sortitems.reverse();
+ }
+
+ for(var i=0;i<sortitems.length;i++) {
+ this.addAt(sortitems[i].item,i);
+ }
+};
+