cancel
Showing results for 
Search instead for 
Did you mean: 

Table control

Former Member
0 Kudos

Hi,

How to add columns(fields) in table control dynamically..

I have a text box..If i choose 3 on the text box it want to display 3 fields in table control..When i press 4 means four fields in table control respectively..

Is it possible..If possible means can u help me with the sample code

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Take one context attribute preSelected of type integer to hold value that is selected previously then

Also create One Value node "Fields" and TableUI Element statically. Bind Table 'datasource' property to this ValueNode.

In doModifyView() method write following clode

IWDNode nodeFields=wdContext.getChildNode("Fields",0);

IWDNodeInfo nodeInfo=nodeFields.getNodeInfo();

wdContext.getContext().reset(false); // for removing dynamic context

int size=wdContext.currentContextElement().get<Number>();

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

nodeInfo.addAttribute("column"+i,"com.sap.dictionary.string");

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

for(int i=0;i<wdContext.currentContextElement().getNoofCols();i++)

{

IWDTableColumn col=(IWDTableColumn)view.getElement("col"+i);

if(col!=null)

col.destroy();

}

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

{

IWDTableColumn col=(IWDTableColumn)view.createElement(IWDTableColumn.class,"col"+i);

IWDCaption caption=(IWDCaption)view.createElement(IWDCaption.class,"cap"+i);

caption.setText(strNames<i>);

col.setHeader(caption);

col.setWidth("100px");

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

text.bindText("Fields.column"+i);

text.setWrapping(true);

col.setTableCellEditor(text);

table.addColumn(col);

}

Regards

LN

Edited by: Lakshmi Narayana Chowdary Namala on Jun 23, 2008 11:26 AM

Former Member
0 Kudos

Hi Mahesh,

I guess the Table is bound to a context which has all the records, in the sense, more than 4 records. Else bound the context which has all the records required to display. This is alternative solution to what was given above, Please do the following.

1. if you check the table property, you will find a property called "VisibleRowCount" . 2. Create a ContextValue in root node of Type integer.

3. Set this context some default value and map this context value in Table "VisibleRowCount" property.

4.When Ever the number of records to be displayed in selected in text Box, Set the number in context Mapped to VisibleRowCount Property.

You code might look like this

sample Context Value name : RowCount

In the action method, write the following

int rowCount = Integer.parseInt(wdContext.node.. )(fetch value from text box(text field/area)

wdContext.currentContextElement().setRowCount(rowCount);

(RowCount is a sample Context Value created in roor node)

Hope it helps.

nikhil_bose
Active Contributor
0 Kudos

try this code in wdDoModifyView():

1) I placed Table in view with id Table.

2) binded table to an empty node Table


int numberOfCols = 4;
    if(firstTime){
    	IWDTable table = (IWDTable)view.getElement("Table");
    	IWDTableColumn column;
    	IWDTableCellEditor celleditor;
    	IWDNodeInfo nodeinfo = wdContext.nodeTable().getNodeInfo();
    	IWDInputField input;
    	IWDCaption header;
    	IWDAttributeInfo attrinfo;
    	for(int i=0; i<numberOfCols; i++){
    		column = (IWDTableColumn)view.createElement(IWDTableColumn.class,new String("col"+i));
    		input = (IWDInputField)view.createElement(IWDInputField.class,new String("inp"+i));
    		celleditor  = (IWDTableCellEditor)input;
    		header = (IWDCaption)view.createElement(IWDCaption.class,new String("head"+i));
    		column.setHeader(header);
    		header.setText(""+i);
    		column.setTableCellEditor(celleditor);
    		attrinfo = nodeinfo.addAttribute(new String("atr"+i), "com.sap.dictionary.string");
    		input.bindAlignment(attrinfo);
    		table.addColumn(column);
    	}
    }

refer this [document|http://www.lowgren.net/mikaell%C3%B6wgren-blog-dynamicgui] on dynamic UI generation.

[Dynamic context creation|] thread

nikhil

Former Member
0 Kudos

Hi,

Iam not sure what is that text box u r talking about?but certainly u can add columns to the table dynamically.



IWDTable table = (IWDTable)view.getElement("Your table name");

IWDCaption header1 = (IWDCaption)view.createElement(IWDCaption.class,null);

IWDTableColumn column1 = (IWDTableColumn)view.createElement(IWDTableColumn.class, null);

IWDTextView editor1 = (IWDTextView)view.createElement(IWDTextView.class, null);

header1.setText("Any heading u want to display");

editor1.bindText("Your Node name"+".Your Attribute name");

column1.setTableCellEditor(editor1);

column1.setHeader(header1);	
table.addColumn(column1);

regards

Surender dahiya