cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete(remove) one row(record) from a dynamic table

Former Member
0 Kudos

Hi,

I have adynamically created table.

I want to delete 1 record(Row) from that Dynamic table.

Say if my dynamic table contains 5 records(rows);after deletion of 1 record(1 complete row)from that dynamic table,the number of records(rows) should be 4 .

Please suggest me how to proceed.

Please provide me some sample code.Its not working

-


I tried with these code:-Its not working-->

IPrivateExportexView.IEt_WriteoffNode node=wdContext.nodeEt_Writeoff();

IPrivateExportexView.IEt_WriteoffElement nodeEle= node.createEt_WriteoffElement(new Zfrm_Writeoff_P());

node.removeElement(nodeEle);

-


Please suggest

Thanks

-Sandip

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

*int n=wdContext.nodeTable().getLeadSelection();*

*wdContext.nodeTable().removeElement(wdContext.nodeTable().getTableElementAt(n));*

Further more , an example is given below for better understanding , do modifications according to your need.

node :

value node - Table (cardinality - 0..n , selection 0..1)

no ( value attribute - string )

name (value attribute - string )

// create node elements

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

{

IPrivateClearnodeElements.ITableNode node = wdContext.nodeTable();

IPrivateClearnodeElements.ITableElement ele = node.createTableElement();

ele.setNo((101i)"");

ele.setName("name :"(i1));

node.addElement(ele);

}

// Apply template Table -- select -- table node or

// create a table UI element and set the property Datasource - Table ( of the context)

Insert Colum , in that column, next insert celleditor , of type text view , bind the property text -- to "name " of Table node of the context

Insert Colum , in that column, next insert celleditor , of type text view , bind the property text -- to "no " of Table node of the context

// create a action "removeElement"

// create a button "Remove Element " --> Event action -- removeElement

// under the action write down the code :

public void onActionremoveElement(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionremoveElement(ServerEvent)

// before removing display elements

wdComponentAPI.getMessageManager().reportSuccess("Before deletion :");

for(int i=0;i<wdContext.nodeTable().size();i++)

{

wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getNo()) ;

wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getName()) ;

}

int n=wdContext.nodeTable().getLeadSelection();

wdContext.nodeTable().removeElement(wdContext.nodeTable().getTableElementAt(n));

// After deletion

wdComponentAPI.getMessageManager().reportSuccess("After deletion :");

for(int i=0;i<wdContext.nodeTable().size();i++)

{

wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getNo()) ;

wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getName()) ;

}

//@@end

}

If helpful , give points .

Let me know if any problem u face .

Thanks,

Srini

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi srinivasa/Lavanya/pinki/Ayyapparaj.

Thanks for accurate answer.Marks given to u.

Regards

-Sandip

Former Member
0 Kudos

Hi,

their no difference in the code for deleting record from a dynamic table or static table.

Only thing you need to take care is that you need to get the leadselection if you are deleting records based on the user selection.

For this purpose use the following code

wdContext.node<Your Node bound to the table>().getLeadSelection();

Ex:

int x = wdContext.nodeOrders().getLeadSelection();

To delete the selected record

wdContext.nodeOrders().removeElement(

wdContext.nodeOrders().getElememtAt(x));

Regards

Ayyapparaj

Former Member
0 Kudos

hi,

For deleting arow, you have to select that row in runtime.....so the row has to be selected at first.

Then put in the following code:

//@@begin onActionDeleteProduct(ServerEvent)

int n = wdContext.nodeProducts().size();

int leadSelected = wdContext.nodeProducts().getLeadSelection();

// loop backwards to avoid index troubles

for (int i = n - 1; i >= 0; --i) {

if (wdContext.nodeProducts().isMultiSelected(i) || leadSelected == i) {

wdContext.nodeProducts().removeElement(wdContext.nodeProducts().

getElementAt(i));

}

Former Member
0 Kudos

Hi ,

Dynamically u cant remove the column in a table.

U can add one button column in the table.

Onclickbutton u can add the functionality to remove the row from that table.

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

{

//Get the leadSelection

int leadSel = wdContext.nodeTable().getLeadSelection();

tableElement.removeElement(wdContext.nodeTable().getTableElementAt(leadSel));

}

Regards,

Lavanya G