0

Insert row after particular row in a grid

asked 2010-12-23 05:19:26 +0800

ashishchoudhary gravatar image ashishchoudhary
21 1

Hi All.

How can I insert a new row in already existing grid after a given row?
The scenario is tht I have certain number of rows in a grid and one of the row has a toolbarbutton,on click of which a new row has to be inserted just after that particular row.
Use of append() method will add the row to last of the grid so I can't use it.Is there any way insertBefore() can be used in this scenario.
Plz note tht I only hav the row which has the toolbarbutton.

Any kind of help will be appreciated...

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2010-12-23 07:07:54 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

Hi,

you can use a combination of parent and nextSibling:

<zk>
 <grid>
  <rows>
   <row><label value="A"/></row>
   <row id="target"><label value="B"/></row>
   <row><label value="D"/></row>
  </rows>
 </grid>
 <zscript>
 Row row = new Row();
 row.appendChild(new Label("C"));
 target.getParent().insertBefore(row, target.getNextSibling());
 </zscript>
</zk>

HTH, Maik

link publish delete flag offensive edit

answered 2010-12-23 22:38:43 +0800

ashishchoudhary gravatar image ashishchoudhary
21 1

Thanks for help...

link publish delete flag offensive edit

answered 2010-12-24 01:55:30 +0800

ashishchoudhary gravatar image ashishchoudhary
21 1

The reference manual for insertBefore(Component newChild, Component refChild) says tht if refChild is null then in tht case, new row will be appended to the end but in my case its shouting for NullPointerException.I am using following syntax:

targetRow.getParent().insertBefore(newrow,targetRow.getNextSibling());

it works fine if there exists a row after the targetRow otherwise throw NullPonterException

link publish delete flag offensive edit

answered 2010-12-24 02:12:45 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

Hi,

which ZK version do you use? I've just tried my example in the ZK-Sandbox (running 5.0.5) without row "D" and it works as expected.

Cheers, Maik

link publish delete flag offensive edit

answered 2010-12-24 02:53:43 +0800

ashishchoudhary gravatar image ashishchoudhary
21 1

Hi Maik.

I got where the problem was...
I was not properly addressing the targetRow coz of which NullPointerException was being thrown.

Nyways thanks..

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-12-23 05:19:26 +0800

Seen: 746 times

Last updated: Dec 24 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More