Skip to Content
avatar image
Former Member

How to populate IWDTable programatically

Hi,

I am struggling with populating the IWDTable with the data that I porcessed in run time. At design time, I can define what my table looks like with all the columns etc.

Say, at run time, I process my data and put them in a list, example. How do I populate my table with the data I have?

From what I have read so far, look like I need to populate the table column by column instead of row by row (is that correct?). I may also need to use wdContext to holde my data first and use something like IWDTextView.bindtext("my context path") etc. Not sure if I am in the right track.

Any code sample will be greatly appreciated. This is for the 7.1 version.

Thanks!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Mar 18, 2009 at 04:44 AM

    Hi

    Ya you have to populate column data , and You have to use Context to hold your data (The purpose of context to serve the data as well as place holder)

    Take code help from [this |create-dynamic-table; and [this|creating-dynamic-tables;

    Best Regards

    Satish Kumar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 18, 2009 at 04:47 AM

    Hi,

    See this code

    	  // taking the transparent container
    	  IWDTransparentContainer container = (IWDTransparentContainer)view.getElement("RootElement");
    	  
    	  // Create an element of Table
    	  IWDTable iTabFinal = view.createElement(IWDTable.class, "theDecisionTable");
    
    	  
    	  // Bind data source of table.
    	  iTabFinal.bindDataSource("<YOUR_NODE_NAME>");
    	  iTabFinal.setVisibleRowCount(10);
    	  iTabFinal.setWidth("90%");
    	  iTabFinal.setFixedTableLayout(true);
    	  
    	  // Iterate over the node which is binded to table.
    	  Iterator itrElement = wdThis.wdGetContext().node<YOUR_NODE_NAME>Node().getNodeInfo().iterateAttributes();
    	  int index = 1;
    	  while(itrElement.hasNext())
    	  {
    		  IWDAttributeInfo iWDInfoElements = (IWDAttributeInfo) itrElement.next();
    		  String colName = iWDInfoElements.getName();
    
    		  IWDTableColumn iTabColFinal = view.createElement(IWDTableColumn.class,null);;
    
    
    		  IDataType attrDataType = iWDInfoElements.getDataType();
    		  String type= attrDataType.getName();
    		  IWDCaption iCapFinal = view.createElement(IWDCaption.class,null);
    
    		  // I HAVE USED LINK TO ACTION AS CELL EDITOR... YOU CAN USE ANYTHING.
    		  IWDLinkToAction lnk = view.createElement(IWDLinkToAction.class,"lnk_"+index);
    
    		  lnk.bindText("AttributeNode."+iWDInfoElements.getName());
    		  lnk.setOnAction(popUp);
    
    		  iCapFinal.setText(<SOME DESCRIPTION>);
    		  
    		  // Set the column design. Not mandatory
    		  WDTableCellDesign cellDesign = null;
    		  iTabColFinal.setCellDesign(cellDesign.CRITICALVALUE_LIGHT);
    		  iTabColFinal.setHeader(iCapFinal);
    
    		  iTabFinal.addGroupedColumn(iTabColFinal);
    		  index++;
    	  }
    	  container.addChild(iTabFinal);
    

    I hope this helps! If you need any help please let me know.

    Regards

    Pravesh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 18, 2009 at 04:56 AM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 18, 2009 at 09:59 AM

    A Table UI element needs a data source node. This can be any context node of cardinality 0:N. The elements in this node provide the rows of the table.

    Each table column defines a cell editor (e.g. InputField, TextView, CheckBox etc). The properties of each cell editor can be bound to the attributes of the data source node.

    To fill a table at runtime, you just fill the data source node. The rest happens automatically using the defined data binding of the cell editors.

    Armin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 18, 2009 at 01:55 PM

    Thanks for your quick responses.

    My actual question is not dynamically creating the table itself. The table and its columns are there. I need to find a way to bind the data I process at run time (in a collection, e.g. ArrayList) to the columns that I have already created.

    How would I create (or use) Nodes at run time in the wdContext to hold my data in these collections and then bind it to the columns I have?

    Thanks again.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      You don't need to create nodes, only elements in the data source node. If the data source node is named "Rows" and has an attribute "name", you do this like

      IRowsElement e = wdContext.nodeRows().createAndAddRowsElement();
      e.setName("some name");
      

      Armin

  • avatar image
    Former Member
    Mar 18, 2009 at 09:56 PM

    I finally got it to do it. Thank you all for your help.

    Add comment
    10|10000 characters needed characters exceeded