cancel
Showing results for 
Search instead for 
Did you mean: 

Create table columns and rows dynamically

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi,

I want to create a table with variable number of records and columns dynamically.

At runtime of the application, user is going to select number of columns and based on the input , I need to create table with that no of columns. Also how can I display multiple records in that table with out using any context nodes or elements.

Thanks in advance

Regards

Suresh KB

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

First of all u cannot create a display multiple records in a table without a Context node and attributes. The number of elements under a Context Node is the number of rows in a table.

Now to create a table dynamically follow these steps:

1. Create a Value Node.

2. Create and add 'n' Value Attributes according to ur need.

3. Create IWDTable object.

4. Create IWDTextView objects.(same number as that of Value Attributes)

5. Bind the text property of IWDTextView object to that of the Value attribute.

6. Create and add 'n' IWDTableColumn according to ur need. (same number as that of Value Attributes)

7. setTableCellEditor of the IWDTableColumn object with IWDTextView object.

Its done.

Now code:

1. Create Node:

IWDNodeInfo nodeInfo = wdContext.getNodeInfo().addChild("TableNode",null,true,true,false,false,false,true,null,null,null);

2. Add Attribute: Put in a loop (int i) to create 'n' attributes.

IWDAttributeInfo attInfo = nodeInfo.addAttribute("attr"+i,"datatype");

or

IWDAttributeInfo attInfo = wdContext.getChildNode("TableNode",IWDNode.LEAD_SELECTION).getNodeInfo().addAttribute("name"+i,"datatype");

3. Create Table:

IWDTable table = (IWDTable)view.createElement(IWDTable.class,"ID");

4. Create CellEditor (TextView):

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

5. Bind attribute to the TextView:

txtView.bindText(wdContext.getChildNode("TableNode",IWDNode.LEAD_SELECTION).getNodeInfo().getAttribute("attr"+i);

6. Create Column:

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

7. Set CellEditor of Column:

col.setTableCellEditor(txtView);

8. Add the Column to the Table:

table.addColumn(col);

Code to create Nodes and attributes can be written in wdDoInit() and rest in wdDoModify(). U have to take care of the loop.

Now u create elements of this node and add to it. It will be reflected as rows of the table.

IWDNodeElement dynEle = wdContext.getChildNode("TableNode",IWDNode.LEAD_SELECTION).createElement();

dynEle.setAttributeValue("attr"+1,"data");

wdContext.getChildNode("TableNode",IWDNode.LEAD_SELECTION).addElement(dynEle);

Regards,

Piyush.

suresh_krishnamoorthy
Active Contributor
0 Kudos

Thanks a lot guys.

Regards

Suresh KB

Former Member
0 Kudos

Suresh,

Small reminder to you:

VS

Answers (2)

Answers (2)

former_member182372
Active Contributor
0 Kudos

Hi Suresh,

There is couple of approaches to achieve your goal.

If set of columns is well known on design time you can create all of them and define visibility attribute in context.

If set of columns is not well known on design time you can create columns dynamically. See tutorial "How to use dynamic programming in Web Dynpro applications?" https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/web dynpro tutorial and sample applications.faq#q-17.

It is not possible to load data to table without using data source node.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi,

as far as I know,

you need Context nodes.

Because the data is stored in the Context.

For the Gui you need the Context for the table data.

You can't save data direct in the Gui.

Patrick