cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Table Dynamicaly

Former Member
0 Kudos

Hi guys,

I'd like to create table in a pop-up window dynamicaly. The problem is that I know number of columns only in the run-time in according to RFC return value, which give me the number of columns needed in the table. I the controller I execute RFC (ABAP function) and then fire event with "numberColumn" parameter. The event is handled in the View. In the View then I need to create Table with specified by "numColumn" columns.

How to do that ?

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This is my code. It works - create table with 5 columns. But all rows in the table contain a data from last nodeElement. Why ?


		IWDTableColumn tc = null;
		IWDTableCellEditor tce = null;
		IWDCaption cap = null;
		IWDNodeElement nodeElement = null;
		IWDCaption capinp = null;
		IWDButton button = null;
		IWDTextView tw = null;
		IWDTransparentContainer cont = (IWDTransparentContainer)view.getElement("TransparentContainer1");
		
		IWDTable table = (IWDTable)view.createElement(IWDTable.class,"TABLE1");

		table.bindDataSource("SLData");
		cont.addChild( table );

		
		///////////////////////////////////////////
		IWDTableColumn tc0 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"Col0");
		cap = (IWDCaption)view.createElement(IWDCaption.class,"Capt0");
		cap.setText("Seiousness / Likelihood");
		tc0.setHeader(cap);
		table.addColumn(tc0);
		
		///////////////////////////////////////////
		IWDTableColumn tc1 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"Col1");
		cap = (IWDCaption)view.createElement(IWDCaption.class,"Capt1");
		cap.setText("Col1");
		tc1.setHeader(cap);
		table.addColumn(tc1);
		
		///////////////////////////////////////////
		IWDTableColumn tc2 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"Col2");
		cap = (IWDCaption)view.createElement(IWDCaption.class,"Capt2");
		cap.setText("Col2");
		tc2.setHeader(cap);
		table.addColumn(tc2);
		
		///////////////////////////////////////////
		IWDTableColumn tc3 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"Col3");
		cap = (IWDCaption)view.createElement(IWDCaption.class,"Capt3");
		cap.setText("Col3");
		tc3.setHeader(cap);
		table.addColumn(tc3);
		
		///////////////////////////////////////////
		IWDTableColumn tc4 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"Col4");
		cap = (IWDCaption)view.createElement(IWDCaption.class,"Capt4");
		cap.setText("Col4");
		tc4.setHeader(cap);
		table.addColumn(tc4); 

		int size = wdContext.nodeSLData().size();
		
		for (int i = 0, j = 0; i < size; i++) {
			nodeElement = wdContext.nodeSLData().getElementAt(i);
			
			tw = (IWDTextView)view.createElement(IWDTextView.class, "TextView" + i);
			tc0.setTableCellEditor(tw);
			tw.setText(nodeElement.getAttributeAsText("seriousnessText"));

			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("I"));
			tc1.setTableCellEditor(button);
				
			j++;
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("II"));
			tc2.setTableCellEditor(button);
			
			j++;
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("III"));
			tc3.setTableCellEditor(button);
			
			j++;
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("IV"));
			tc4.setTableCellEditor(button);
			
			j++;
		}

Former Member
0 Kudos

Hi,

No need to use the for loop...use Bind methods for the TableCellEditors

Ex :

tw = (IWDTextView)view.createElement(IWDTextView.class, "TextView" + i);

tc0.setTableCellEditor(tw);

tw.bindText( );

Regards,Anilkumar

Former Member
0 Kudos

This code is wrong:

		int size = wdContext.nodeSLData().size();
		
		for (int i = 0, j = 0; i < size; i++) {
			nodeElement = wdContext.nodeSLData().getElementAt(i);
			
			tw = (IWDTextView)view.createElement(IWDTextView.class, "TextView" + i);
			tc0.setTableCellEditor(tw);
			tw.setText(nodeElement.getAttributeAsText("seriousnessText"));
 
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("I"));
			tc1.setTableCellEditor(button);
				
			j++;
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("II"));
			tc2.setTableCellEditor(button);
			
			j++;
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("III"));
			tc3.setTableCellEditor(button);
			
			j++;
			button = (IWDButton)view.createElement(IWDButton.class, "Button" + j);
			button.setText(nodeElement.getAttributeAsText("IV"));
			tc4.setTableCellEditor(button);
			
			j++;
		}

Instead you have to create the table cell editor only once for each column and bind it to the attribute under the data source node that should be displayed in this column.

For example:

IWDTextView editor = (IWDTextView) view.createElement(IWDTextView.class, null);
editor.bindText("SLData.seriousnessText");
tc0.setTableCellEditor(editor);

Armin

Answers (2)

Answers (2)

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi Stefen,

in wdModifyView() you can add elements dynamically at runtime.

IWDUIElementContainer cont = (IWDUIElementContainer) view.getElement("RootUIElementContainer"); // your root ui element id of the layout

IWDTable tab = (IWDTable) view.createElement( IWDTable.class, "tab_1");

cont.addChild( tab );

use tab.addColumn() to add columns dynamically.

For More Information go through the link

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489...

Regards

Abhimanyu L

Former Member
0 Kudos

Hi Stefan,

Please go through <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7f531207-0301-0010-5f9c-8652a3232ae0">this</a> PDF.

It has got an exaple of creating Table UI dynamically.

Thanks and Regards,

Mausam