Hi Derrell, 

 

sorry for taking your time, but I can’t figure it out. That is my function:

 

sortByColumn : function(tree, col)

{

                var clazz = this;

                tree.resetSelection();

                var dm = tree.getDataModel();

                function sortByTime(a, b) {

                               var x = a.time.toLowerCase();

                               var y = b.time.toLowerCase();

                               return ((x < y) ? -1 : ((x > y) ? 1 : 0));

                }

 

                var data = dm.getData(); // Current Tree Data

                var newData = new Array(); // new Tree Data

                for (i=0; i<data.length; i++)

                {

                               if (data[i] == null)

                               {

                                               var newNode = null;

                               }

                               else

                               {

                                               var newNode =
qx.lang.Object.clone(data[i]);

                               

                                               var children =
data[i].children;

 

                                               var sortTime = new Array();

                                               

                                               if (data[i].type == 2 &&
children.length>1) // Nur Kindelemente sortieren, wenn Node ein Branch und
Anzahl Kindelemente mehr als 1

                                               {

                                                               var childTime
= new Array(); // Hier wird ein zu sortierendes Array erstellt; time:
'18:30', node : OBJECT

                                                               for (x=0;
x<children.length; x++)

                                                               {

 
var cNodeId = children[x]; // Node Id des Kindelements

 
var cNode = tree.nodeGet(cNodeId); // Hier landet das Kindelement

 
childTime.push(

 
{

 
time: cNode.columnData[1],

 
node: cNode

 
}

 
);

                                                               }

 
childTime.sort(sortByTime); // Sortiere anhand von Time

                                                               var
sortchilderen = new Array(); // neue Node id Reihenfolge erstellen für
children

                                                               for (a=0;
a<childTime.length; a++)

                                                               {

 
sortchilderen.push(childTime[a].node.nodeId);

                                                               }

                                                               

 
newNode.children = sortchilderen;

                                                               

                                               }

                               }


 

                               newData.push(newNode);

                }

                dm.setData(newData);

},

 

It works fine, but with a null in the tree array it crashes. Could you tell
me a better way to sort leafs?

 

Regards Sak

 

Von: Derrell Lipman [mailto:derrell.lip...@unwireduniverse.com] 
Gesendet: Donnerstag, 14. Oktober 2010 15:05
An: qooxdoo Development
Betreff: Re: [qooxdoo-devel] virtual tree pune sets NULL, but setData dont
accepts NULL in nodeArray

 

On Thu, Oct 14, 2010 at 06:33, Mustafa Sak <i...@saksys.de> wrote:

Hi Derrell,

 

just now I tried your advise:

You indicated that you passed the modified array. That is incorrect. You do
not pass the altered array to setData(). Instead, you simply call
setData(NULL). When it renders the data, it skips nodes that are null:

 

            // Skip deleted nodes

            if (child == null)

            {

              continue;

            }

 

 

But there is no skipping.

 

tree.getDataModel().prune(nodeId, true);

console.log(tree.getDataModel().getData());

tree.getDataModel().setData(null);

console.log(tree.getDataModel().getData());

 

Because of the null elements of the array, my sortfunction doesn’t work
proper. So did I understand you wrong? Is there no way to clear the NULL
elements?

 

The nulls will still be in the data model, but they will not be rendered.
What are you sorting and why do the nulls affect your sort function? They'd
all sort to the same place, and then be ignored while rendering...???

 

The nulls can not be removed from a data model. The ordinal position in the
data model array is the handle that identifies a node. If the nulls were
removed, the location in the array would change, causing any saved handles
to now point to different nodes. Each node has a 'children' array which
contains the handle of the nodes which are children of this one. If you were
to remove an element of the array, all of those children handles would be
off by one. That would be bad. The wrong nodes would now be displayed as
children.

 

If you are doing lots and lots of pruning, you might consider writing a
different data model class that handled references to other nodes
differently, so that deletions could actually remove the element from the
array.

 

I hope that makes more sense to you now.

 

Derrell

 

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to