cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic table columns

Former Member
0 Kudos

Hi all,

I have a no dynamic table, now I need add a dynamic columns a this table, I don't know the numer of columns until the user does not select a series of pre-filters.

How can I modify mi table? I have crate all table dynamically or can I to create dynamically only some columns?

Thanks and regards!!

Accepted Solutions (1)

Accepted Solutions (1)

Sharathmg
Active Contributor
0 Kudos

You can do both, create the whole table dynamically or add columns to an existing table.

You will have to write all the dynamic code within the wdModifyView() method. Only in this method, will you get the handler for the existing view(parameter variable). Using the Interfaces for table and column, build a whole table or add columns to the table.

Check the IWDTable javadocs for further help:

http://help.sap.com/javadocs/nwce/ce711sp02/wdr/com.sap.wdr/com/sap/tc/webdynpro/clientserver/uielib...

Also check out dynamic coding in Web Dynpro java for further guidance on this topic.

Regards,

Sharath

Former Member
0 Kudos

Hi Sharath,

I have a button called Search and I have defined a method onactionSearchlist. The user will press this button when he has selected search filters.

This method read the search filters and show the search table.

Can I add dynamic columns in my table in this method onactionSearchlist??

If I add dynamic columns in wdModifyView() method, my table will be updated with the new columns when I press search button?

Thanks!

Mónica

Sharathmg
Active Contributor
0 Kudos

As I understand, you have some search criteria(s)/filters presented to the user. Based on the entry and subsequent click of button, you would like to display a table with data relevant to the filters.

In order to provide a solution which is easier to manage and with better performance, I would suggest you to make use of visibility property of the UI element. Here is how it could be developed:

1. Design a table with all the columns, available to be displayed to the user i.e. when all filters are selected.

2. Define context property of type WDVisibility, one for table and each one for the columns who may be hidden/displayed based on the filters selected by user.

3. Assign these variables to the visibility property of the table and relevant columns, respectively.

4. By default(init method), set the value to WDVisibility_NONE.

5. In the action linked to button, based on your logic, set the columns to be shown as WDVisibility_VISIBLE and rest of the columns to WDVisibility_NONE. The table however has to be set to WDVisibility_VISIBLE.

The dynamic code is resource intensive and delays the screen rendering process. You may find some issues but its a far easier way to implement than loading the screen elements at every click, which is also possible.

Best Regards,

Sharath

Former Member
0 Kudos

Hi,

I know some columns but I have a filter containing companies, one company have a certain number of areas but this number is different in each company,

These areas are my problem I don't know the number of areas  each area is a new column.. but the areas number can change in the future.

For that reason asked in my previous post if I have to add dynamic columns in the wdModifyView() method or also can I add dynamic columns in button method?

Thanks!

Regards

Mónica

Sharathmg
Active Contributor
0 Kudos

In my understanding, the wdModifyView method gets called on any action, too.

You could set some variables, which should be verified within wdModifyView method. Based on the set variables, build a column and add it to the existing table in the view.

Regards,

Sharath

Answers (1)

Answers (1)

govardan_raj
Contributor
0 Kudos

hi Gonzalez ,

    IWDView reportView = wdContext.current********Element().get******View();

  

   

    IWDTable existingTable = (IWDTable)****View.getElement("ExistingTable");

    int order = 1;

    for(int count = 0; count < wdContext.nodecolumnCount().size();count++)

    {

            IWDTableColumn tableColumn = (IWDTableColumn)****View.createElement(IWDTableColumn.class, "column"+order);

      IWDCaption Caption = (IWDCaption)****View.createElement(IWDCaption.class,"Caption"+order);

    

      // wdComponentAPI.getMessageManager().reportSuccess("The Display Column Name is "+wdContext.nodeColumnCount().getColumnCountElementAt(count).getColumnDisplayName());

   

    

      Caption.setText(wdContext.nodeColumnCount().getColumnCountElementAt(count).getColumnDisplayName());

      tableColumn.setHeader(Caption);

      IWDTextView columnTextView = (IWDTextView)****View.createElement(IWDTextView.class, null);

      IWDAttributeInfo attributeInfo =  wdContext.nodeColumnCount().getColumnCountElementAt(count).getColumnAttrInfo();

      columnTextView.bindText(attributeInfo);

      tableColumn.setTableCellEditor(columnTextView);

      tableColumn.bindFilterValue(wdContext.nodeColumnCount().getColumnCountElementAt(count).getFilterValueAttrInfo());

      existingTable.addColumn( tableColumn );

      order = order + 1;

    

         }

you can use the above code , it is best practise to create dynamic ui elements at wdModifyview , but in case if it is necessary to create on click of button or some action you can assign reference of the view (of type iwdview) from wdmodify view method to global variable which is of type IWDView or in context create an attribute of type Iwdview and use that for creating a dynamic columns .

here ExistingTable is the name of the table for which you have to add dynamic columns , have any doubts please post ill help to resolve and you can use this code at the action  when you can determine the number of columns from the filters.

Regards

Govardan Raj