cancel
Showing results for 
Search instead for 
Did you mean: 

Creation of table, columns dynamically

Former Member
0 Kudos

Hi All,

Im pretty new to WebDynpro can you please help me with some code samples for the below problem,

I have two Collection variables namely, <b>"fieldList"</b> and <b>"Records"</b>

<b>fieldList has the all the field names of the table

Records has all the records in my table</b>

Note : fieldList, Records are dynamic

Now i want to create a table dynamically, with fieldList as the columns and Records as the records inside the table created.

How can we do this please advise

Thanks

Suresh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Depends on what you mean by "dynamically". If the table columns are known at designtime, just create the table in the IDE. The table rows are in any case determined at runtime from the content of the data source node.

Armin

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Suresh Devaiah,

While creating any table you have to take care of the datasource Node.

Now over here since you have a collection field list first iterate through that collection and create the Node Say NodeA as follows:


IWDNodeInfo nodeInfo=wdContext.getNodeInfo().addChild("NodeA",null, true, true, false,false, false, true, null,null, null);
IWDNodeInfo childNodeInfo = wdContext.getChild("NodeA").getNodeInfo();
Collection fieldList; //some collection initialize.
Iterator i = fieldList.iterator();
while(i.hasNext()){
childNodeInfo.addAttribute("Fieldname", "com.sap.dictionary.string"/*Field Type*/);
}
// This has created the node and attributes dynamically at runtime.
//Now populating the node.
Iterator j = childNodeInfo.iterateAttributes();
Collection Records; //initialize the collection
Iterator r = Records.iterator();
while(r.hasNext())
IWDNodeElement nodeElement = wdContext.getChildNode("NodeA").createElement(); 
while(j.hasNext()){
nodeElement.setAttributeValue(((IWDAttributeInfo)j.next()).getName,"Set the value from the collection");
}

Now in the wdDoModifyView you'll require to do the following under firstTime(default visibility)


 if(firstTime){
    	IWDTable table = (IWDTable)view.createElement(IWDTable.class,"table");
    	Iterator i = wdContext.getChild("NodeA").getNodeInfo().iterateAttributes();
    	while(i.hasNext()){
    		IWDAttributeInfo attInfo = (IWDAttributeInfo)i.next();
    		IWDTableColumn tableColumn = (IWDTableColumn)view.createElement(IWDTableColumn.class,attInfo.getName()+"column");
    		IWDTextView textView = (IWDTextView)view.createElement(IWDTextView.class,attInfo.getName()+"textView");
			textView.bindText(attInfo);
			IWDTableStandardCell tableCellEditor = (IWDTableStandardCell)view.createElement(IWDTableCellEditor.class,attInfo.getName()+"editor");
    		tableCellEditor.setEditor(textView);
			textView.setVisible(WDVisibility.VISIBLE);
    		tableCellEditor.setVariantKey(attInfo.getName()+"i");
    		tableColumn.addCellVariant(tableCellEditor);
			tableColumn.setVisible(WDVisibility.VISIBLE);
    	}
    	table.bindDataSource(wdContext.nodeA().getNodeInfo());
 
IWDTransparentContainer transparentCont = (IWDTransparentContainer)view.getElement("RootUIElementContainer");
 
transparentCont.addChild(table);
table.setVisible(WDVisibility.VISIBLE);
}

The above code takes care of creating a table dynamically.

Also create some elements for the dataSource node to see the result.

Regards

Amit

Former Member
0 Kudos

Hi,

Check the following threads,coding is there....

Check the following threads....

Former Member
0 Kudos

Hi,

/docs/DOC-8661#34 [original link is broken]

Regards,

Naga