Skip to Content
author's profile photo Former Member
Former Member

Reordering of the nodeelements of a node

Hi All,

Lets say i have a node Test with cardinality 1..n with some attributes name and city,Now lets say the test node size is 10;so this has nodeelement0,nodeelement1,nodeelement2...nodeelement9. so this order will be displayed in view if we attach this to table, but i want to reorder these nodelements of Test node like nodeelement2,nodeelement7,nodeelement1,nodeelement4...nodeelement0 . so my first row of table will be in this order.

i tried swapElements and moveElement of IWDNode but could not find the solution.

for(int i=0;i<n1;i++)

{

ITestElement elementAtI=wdContext.nodeTest().getTestElementAt(i);

if(elementAtI.getName().equalsIgnoreCase("k0"))

{

wdContext.nodeTest().moveElement(i,9);

}

else if(elementAtI.getName().equalsIgnoreCase("k2"))

{

wdContext.nodeTest().moveElement(i,0);

//more elseif conditions

}

}

but at the end the reordering of the elements didnot worked in the order i expected.Please provide your suggestions.

Thanks,

pkv.

Edited by: pkv on Oct 2, 2009 1:28 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Oct 05, 2009 at 05:04 AM

    hi,

    One easy solution for your problem would be to create another node of the same context structure as your table node.

    Add elements to the temporary node in the order you want. Finally invalidate table node and use copyElements() method to copy elements from temporary node to table node.

    Otherwise swapelements()and moveelement() would also work if you use them in a correct way.

    Hope this helps!

    Monalisa

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 02, 2009 at 02:41 PM

    hi pkv,

    even if its a referenced node, you dan use WdContext.nodeTest.invalidate() to clear the node and then loop over the Temp node and add these elements to your nodeTest.

    generally, the logic shlound be in the component controller, not in the view. so the reordering of the contextelements shlould be coded there.

    please award points for helpful answers.

    best regards,

    christian

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Armin,

      You wrote, "I don't want to discuss that with you again". The words "with you again" tells me, that we should have discussed this already. In this case, I might have got you wrong an you didn't mean it as I understood it.

      But either you see it as "infamy" or not, I don't think, that this nonsense about who is right and hwo wants to be right will help pkv. And surely it won't increase the threadquality.

      best regards,

      Christian

  • author's profile photo Former Member
    Former Member
    Posted on Oct 02, 2009 at 08:55 AM

    hi pkv,

    do you need a hardcoded ordering or would a ascending/descending sorting of the nodes do for you? this could be done much easier than coding an if for every node. for sorting, take a look at this: http://wiki.sdn.sap.com/wiki/display/Snippets/SortingContextNode

    could you explain, in which way your rodering isn't working? do you get ste same result as before ordering? od an almost correct ordering?

    best regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 02, 2009 at 11:51 AM

    your sorting doesnt work for one reason: moveElement() does nocht exchange teh elements. if you have 5 elements

    12345

    and you do moveElement(0,4) you get

    23451 instead of 52341.

    moveElement() moves the element to the desired position and moves all other elements one up or down, depenedent on the relative potition of the moved element before moving.

    what you could do is creating another context node, with the same structure to add the elements.

    then you have to change your program a little.

    first, you have to sort your if statements.

    second, you will add the element to the other context. lets say nodeTemp.

    for(int i=0;i<n1;i++)

    {

    ITestElement elementAtI=wdContext.nodeTest().getTestElementAt(i);

    if(elementAtI.getName().equalsIgnoreCase("k2"))

    {

    wdContext.nodeTemp.addElement(elementAtI);

    }

    else if(elementAtI.getName().equalsIgnoreCase("k0"))

    {

    wdContext.nodeTemp.addElement(elementAtI);

    //more elseif conditions

    }

    }

    in the nodeTemp, you will have your reordered elements. either you take these elements back to your original context, or you use this temporary context to show the data in your table.

    best regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Christian,

      Thanks for your help,i dont need ascending or descending order, i want it in a predefined hardcoded order, and this node Test is a reference from model node, so i copying in to another temp value node in my required order and recopying this to model node may not work.so i am trying to changes the order of the Test node in the component controller and there by using same in the view.

      Thanks,

      pkv

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.