cancel
Showing results for 
Search instead for 
Did you mean: 

Making the certain columns as disable.

Former Member
0 Kudos

I am using a Complex UI Element - Table in my Web Dynpro. I am displaying 5 columns which are editable. i want to make disaable a column dynamically. How can we do that ?

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Manjunath,

Can you even specify as to on which condition you want to make your column as enabled/disabled?

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

In the view, i have month & Year as drop downs. If the User selects February, on 29 columns should get displayed. If he chooses September, 31 columns should get displayed.

uday_gubbala2
Active Contributor
0 Kudos

Hi Manjunath,

Sorry for the late reply was trying to code the desired functionality. Am not sure whether this is a good way of implementing your task or not but just giving out the way I know...

I had created 2 context nodes.

Node: DROPDOWN is used to store the dropdown values (Jan, Feb...)

Node: TABLE is a dummy node with no attributes used for binding to the table

Declare a variable (say GR_TABLE) of type CL_WD_TABLE in attributes tab of your view. Then in the wddomodifyview method just save the reference of your table UI element into this variable. (NOTE: TABLE is the name which I have given for my TABLE UI element in the view)

method WDDOMODIFYVIEW .

check first_time = abap_true.

wd_this->gr_table ?= view->get_element( id = 'TABLE' ).

endmethod.

Now coming to the main part of creating columns dynamically as per the selected month. I have put a pushbutton beside my DropDownByIndex which the user has to select after making a selction. This button triggers the action ONFETCH. We make use of the 2 classes CL_WD_TABLE & CL_WD_TABLE_COLUMN & the methods REMOVE_ALL_COLUMNS & ADD_COLUMN methods for achieving the desired output. But Manjunath my coding does not include creation of binding for the created columns. You will have to try code that yourself. You can find the necessary methods by going through CL_WD_TABLE & CL_WD_TABLE_COLUMN. Hope that this is helpful for you.

Regards,

Uday

Fill the respective month names in order to appear in the DropDownByIndex.

Coding inside the WDDOINIT method:

METHOD wddoinit .

  DATA: lv_node TYPE REF TO if_wd_context_node,
        lt_dropdown TYPE ig_componentcontroller=>elements_DROPDOWN,
        wa_dropdown TYPE ig_componentcontroller=>element_DROPDOWN.

        wa_dropdown-values = 'January'.
        append wa_dropdown to lt_dropdown.

        wa_dropdown-values = 'February'.
        append wa_dropdown to lt_dropdown.
        -
        -
        -
        -
       lv_node = wd_context->get_child_node( name = ig_componentcontroller=>wdctx_dropdown ).
       lv_node->bind_table( new_items = lt_dropdown ).
ENDMETHOD.

Coding for ONFETCH action triggered by pushbutton:

METHOD ONACTIONONFETCH .
  DATA: lv_node TYPE REF TO if_wd_context_node,
        lt_dropdown TYPE if_main=>elements_dropdown,
        wa_dropdown TYPE if_main=>element_dropdown,
        lead_selection_index TYPE i,
        lr_column type ref to cl_wd_table_column.

  wd_this->gr_table->REMOVE_ALL_COLUMNS( ).
  
  lv_node = wd_context->get_child_node( name = 'DROPDOWN' ).
 
  CALL METHOD lv_node->get_static_attributes_table
    IMPORTING
      table = lt_dropdown.

  lead_selection_index = lv_node->get_lead_selection_index( ).
  READ TABLE lt_dropdown INTO wa_dropdown INDEX lead_selection_index.

  CASE lead_selection_index.
    WHEN '9' or '11' or '4' or '6'. "Sep, Nov, April, June
      do 30 times.
        lr_column = cl_wd_table_column=>new_table_column( ).
        wd_this->gr_table->add_column( index = sy-index
                                       the_column = lr_column ).
      enddo.
    when '10' or '12' or '1' or '3' or '5' or '7'. " Oct, Dec, Jan, Mar, May, July, Aug
      do 31 times.
        lr_column = cl_wd_table_column=>new_table_column( ).
        wd_this->gr_table->add_column( index = sy-index
                                       the_column = lr_column ).
      enddo.
    when others. " Feb
      do 29 times.
        lr_column = cl_wd_table_column=>new_table_column( ).
        wd_this->gr_table->add_column( index = sy-index
                                       the_column = lr_column ).
      enddo.
  ENDCASE.
ENDMETHOD.

uday_gubbala2
Active Contributor
0 Kudos

Hi Manjunath,

Is the problem resolved or not? If yes then please close off this thread

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

I have not got the exxpected output. I will try again and close the thread. Anyway really thanks for the valuable answer

Former Member
0 Kudos

Hi Uday,

So again we need to bind the table columns manually through code i.e classes ..... Right ? Can i know the classes if possible !!!

Former Member
0 Kudos

see uday, i have directly hard coded the 31 columns. Now depending on the month, we need to gray out / disable the 29,30,31 columns.

uday_gubbala2
Active Contributor
0 Kudos

Hi Manjunath,

If you have directly coded all the 31 columns then its easy. You will just have to use the column id for your requirement. You can do it as follows:

You should just specify the ID/INDEX of the column that you want to remove and then you can remove it from your table.

First try with the remove_column( ) and if you get an NULL pointer assignment dump then go for the remove_grouped_column( ) method. ( You can find the reasons in this [thread|;. )

Please find a sample code extract as below:

(m_table is an view attribute of type cl_wd_table. I have saved the reference of the table into this variable in the WDDOMODIFYVIEW method)

" To remove the column using ID
wd_this->m_table->remove_column( id = 'TABLE_CARRNAME_EDITOR' ). 

" Or you can pass the column number using INDEX instead. Below code gets the reference of 3rd column
lr_column = wd_this->m_table->remove_column( INDEX = 3 ).

Hope that this helps resolve your problem.

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

i have the TABLE_DATA2 in the view. Can you write the sample code. I am a bit confusing.

Former Member
0 Kudos

I am trying to get the table instance in the MODIFYVIEW. here is the code. i am getting the null reference.

data: obj_table type ref to cl_wd_table.

obj_table ?= view->get_element( 'TABLE_DATA2' ).

Former Member
0 Kudos

Hi Uday,

i am getting the reference. with the below code

obj_table ?= view->get_element( 'TABLE' ).

Now i tried to remove the column . i used the remove column method. but no result. here is my code.

CALL METHOD obj_table->remove_column

EXPORTING

id = `TABLE_DAY31`

  • index =

receiving

the_column = THE_COLUMN .

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

A couple of warnings about the advice that has been given. First it is suggested that you get a reference to the table during the WDDOMODIFYVIEW and then manipulate it dynamically later in your event handler. This is a violation of the Web Dynpro Phase Model and is highly recommended by SAP that you do NOT follow this advice. This can lead to problems or inconsistencies down the road for which SAP will not be responsible. All dynamic manipulation must occur in the WDDOMODIFYVIEW.

Second, I don't see why you need dynamic logic at all. Why do the remove_column or add the columns dynamically? Just add all the columns at design time. Then use data binding on the columns' Visible property. Control which columns are visible by manipulating the context attribute and not the UI elements themselves. You should always strive to use context bindings for such dynamic manipulation first and only reserve the programatic approach as a last resort.

Answers (1)

Answers (1)

former_member196517
Contributor
0 Kudos

In WDMODIFYVIEW use method SET_VISIBLE of class CL_WD_TABLE_COLUMN