cancel
Showing results for 
Search instead for 
Did you mean: 

How to add/remove table columns dynamically?

Former Member
0 Kudos

Please help urgently!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

1. Create a Contextattribute of type IWDTable.

2. write the following in "wdDoModifyView" method

IWDTable tab=(IWDTable)view.getElement("<<TableID>>");

wdContext.currentContextElement().setTable(tab);

3. Create an action and write the following

tab.removeColumn(<<IndexNo>>) and pass indexnumber from outside

Regards, Anilkumar

Former Member
0 Kudos

Hello,

I dont see the possibility to create an attribute of type TWDTable?

Answers (3)

Answers (3)

Former Member
0 Kudos

Dear at all,

thank you for you suggestion. Through your help I solved the problem by my own.

Thank you!!!

Former Member
0 Kudos

Mehmet,

1. Create context attribute ColumnToRemove (string)

2. In action handler assign the value to this attribute

3. In wdDoModifyView do the following:


final String colID = wdContext.getColumnToRemove();
if ( null != colID )
{
  wdContext.setColumnToRemove(null);
  final IWDTable table = (IWDTable)view.getElement("myTable");
  final IWDTableColumn col = table.removeColumn("colID");
  col.destroy();
}

VS

Former Member
0 Kudos

Make use of removeColumn() method of the table control

Ex: tabl2.removeColumn("<<columnName>>);

or tabl2.removeColumn("<<Index>>);

Regards, Anilkumar

Former Member
0 Kudos

Hi Anilkumar,

how can I do this dynamically through an action??

I.e. I want to add or remove a column only if an appropriet action is triggered?

Former Member
0 Kudos

Don't access the view layout (UI element references) in action event handlers. You have to place this code in wdDoModifyView().

In the action handler, store the information needed (e.g. table column ID, insertion position, whatever) in some context attribute or in some member variable of the view.

In wdDoModifyView(), check if table modification should be done, get the table instance using view.getElement(<tableID>), use the IWDTable API to modify the table.

Finally, reset the flag or configuration data indicating that the table should have been modified.

This is not really elegant, but that's the way it is...

Armin

Former Member
0 Kudos

hello,

the UIEs should not be maniputated in event handlers or methods. all the code should be written in wdDoModifyView().

u create some attributes which decide about the modification of the table. using those parameters u add or remove colomns:

IWDTable table = (IWDTable) view.getElement("tableid");

now u create colomn objects and add them to table object, or remove colomns.

regards,

Piyush.