cancel
Showing results for 
Search instead for 
Did you mean: 

change table column's attribute programmatically

former_member637921
Participant
0 Kudos

Hello,

I have a table that has 10 columns with the same prefix (Labst01,Labst02,...,Labst10) and i get number of columns to display.

I thought of changing programmatically the visible attribute of the columns that are not relevant at the same run result.

Does anyone has a code sample or guidlines?

Thanks

Moshe

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you can make a node with 10 Attributes of the type com.sap.ide.webdynpro.uielementdefinitions.Visibility.

Name the attributes like LabstVisible1, LabstVisible2,...

Then bind the Visibility of the columns to the Context attributes.

At Runtime you can set the Visibility like:


//set every column invisible
for (int i = 1; i <= 10; i++) {
  wdContext.currentVisiblePermissionElement().setAttributeValue("LabstVisible" + i, WDVisibility.NONE);
}
//set columns visible depending on amount of columns
for (int i = 1; i <= countOfColumns; i++) {
  wdContext.currentVisiblePermissionElement().setAttributeValue("LabstVisible" + i, WDVisibility.VISIBLE);
}

For any help, please ask.

Best regards,

Peter

Edited by: Peter Irk on Dec 29, 2009 3:06 PM

Edited by: Peter Irk on Dec 29, 2009 3:07 PM

former_member637921
Participant
0 Kudos

Hi Peter,

first of all thanks for the reply.

i get an error for the "currentVisiblePermissionElement". do you know why?

is it possible to set directly the visible attribute of the column without creating a node?

Former Member
0 Kudos

HI,

have you created the Node VisiblePermissionElement and added at least one Elemen?

You can set the attributes for each column direct in context, but I prefer to keep them in a Node.

If you have the attributes direct in the context, you must use this code:


//set every column invisible
for (int i = 1; i <= 10; i++) {
     wdContext.currentContextElement().setAttributeValue("LabstVisible" + i, WDVisibility.NONE);
}
//set columns visible depending on amount of columns
for (int i = 1; i <= countOfColumns; i++) {
    wdContext.currentContextElement().setAttributeValue("LabstVisible" + i, WDVisibility.VISIBLE);
}

former_member637921
Participant
0 Kudos

Hi,

I understand now that you ment that the name of the node is VisiblePermissionElement, and the second option of setting 10 attributes is also apossibility but i was thinking of setting directly the property "visible" of the table column in the layout directly. Is that possible?

Former Member
0 Kudos

Ah, ok now I know what you mean.

Then I would rename the Columns to Labst1, Labst2, ... Labst10.

Set all Columns to visible in the view.

In the Method wdDoModifyView of the view write this code:


IWDTableColumn col;
for (int i = 10; i > countOfColumnsToDisplay; i--) {
    col = (IWDTableColumn) view.getElement("Labst" + i);
    col.setVisible(WDVisibility.NONE);
}

gill367
Active Contributor
0 Kudos

Hi

You can do this in two ways either by binding all th table columns visiblity property to ten attributes and then programattically setting it.

or you can directly access the table colomn in the wddomodifyview() method and set its visiblity. as shown below:-

 public static void wdDoModifyView(IPrivateTest2View wdThis, IPrivateTest2View.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    IWDTableColumn tc = (IWDTableColumn)view.getElement(<here write the coumn id>);
    tc.setVisible(WDVisibility.NONE);
    
    //@@end
  }

hope this will help

sarbjeet

former_member637921
Participant
0 Kudos

Thanks to both of you it works!!!

Answers (0)