on 01-13-2009 2:41 PM
Hi,
How do i bind/add a inputfield to a tablecolumn dynamic at runtime?
Thanks,
Morten
Have you tried using a cell variant for the column:
http://help.sap.com/saphelp_nw70ehp1/helpdata/en/56/5e9041d3c72e7be10000000a1550b0/frameset.htm
That is really the recommended way of doing dynamic switching between different UI elements within a table cell/column.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a thread with an example where I used a cell variant with two input fields (one with value help and one without). You can substitue many different UI elements and aren't restricture to just use inputFields. This particular example was ALV, but the same thing is actually easier to do with a plain table because you can define the variants at design time in the View Layout tab like all other UI elements. Hopefully this example (and the linked screenshots) give you a better idea of what is possible.
Hi Thomas,
Thanks for your reply.
Still not working. I have the following code:
Hope that you can help me the final step.
DATA:
l_caption TYPE REF TO cl_wd_caption,
l_table TYPE REF TO cl_wd_table,
l_table_column TYPE REF TO cl_wd_table_column,
l_input_field TYPE REF TO cl_wd_input_field,
l_table_cell_var TYPE REF TO cl_wd_abstr_table_cell_var,
l_table_standard_cell TYPE REF TO cl_wd_table_standard_cell.
DATA:
l_node_po_document_lines TYPE REF TO if_wd_context_node,
l_po_document_lines TYPE wdr_context_element_set,
l_po_document_element TYPE REF TO if_wd_context_element.
get all involved child nodes
l_node_po_document_lines = wd_context->get_child_node( 'PO_DOCUMENT_LINES' ).
l_table ?= view->get_element( 'TABLEPURCHASEORDERLINES' ).
l_table_column = cl_wd_table_column=>new_table_column( ).
l_input_field = cl_wd_input_field=>new_input_field( ).
l_input_field->bind_value( path = 'PO_LINES_VIEW.PO_DOCUMENT_LINES.PO_NUMBER' ).
l_input_field->set_enabled( value = abap_true ).
l_table_standard_cell = cl_wd_table_standard_cell=>new_table_standard_cell( ).
l_table_standard_cell->set_editor( the_editor = l_input_field ).
l_table_column->add_cell_variant( EXPORTING the_cell_variant = l_table_standard_cell ).
l_caption = cl_wd_caption=>new_caption( ).
l_caption->set_text( 'Some text' ).
l_table_column->set_header( EXPORTING the_header = l_caption ).
l_table->add_column( EXPORTING the_column = l_table_column ).
Thanks,
Morten
Why are you doing this in code? You can define your cell variants at runtime and just bind the selectedVariant property of the column to a context attribute. That way you can sway the displayed UI element by just changing a context attribute. This approach is much easier and cheaper to maintain in the long run.
In your code you appear to actually be creating a whole new column at runtime. Why are you doing this? It is much better to define all the columns in the layout and just mark a column as hidden. You can do the same thing with a bound context attribute and control the display that way. Such dynamic coding should only be used as an absolute last resort when your entire UI structure needs to be dynamically generated. For such dynamic modifications at runtime you should really just use context binding to the properties of the UI elements.
I made a little adjustment to your code and was able to get it working. I used the set_table_cell_editor method of the column to directly set the inputField into the column. I may have led you wrong originally with the idea of the cellVariant because I misunderstood your original requirement. I thought you wanted to swap dynamically between two different UI elements in the same column - in which case you would need the cellVariant.
I still think that using the ALV would be more efficient, but here is the coding.
METHOD wddomodifyview .
DATA lr_container TYPE REF TO cl_wd_uielement_container.
DATA lr_input TYPE REF TO cl_wd_input_field.
DATA lr_table TYPE REF TO cl_wd_table.
DATA lr_caption TYPE REF TO cl_wd_caption.
DATA lr_table_column TYPE REF TO cl_wd_table_column.
DATA lr_table_standard_cell TYPE REF TO cl_wd_table_standard_cell.
IF first_time = abap_true.
lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
cl_wd_table=>new_table(
EXPORTING
bind_data_source = 'SFLIGHT.SFLIGHT'
id = 'DYNTABLE'
RECEIVING
control = lr_table ).
cl_wd_input_field=>new_input_field(
EXPORTING
bind_value = 'SFLIGHT.SFLIGHT.CARRID'
id = 'INPUT1'
RECEIVING
control = lr_input ).
lr_table_column = cl_wd_table_column=>new_table_column( ).
* lr_table_standard_cell = cl_wd_table_standard_cell=>new_table_standard_cell( ).
* lr_table_standard_cell->set_editor( the_editor = lr_input ).
lr_table_column->set_table_cell_editor( lr_input ).
lr_caption = cl_wd_caption=>new_caption( ).
lr_caption->set_text( 'Some text' ).
lr_table_column->set_header( EXPORTING the_header = lr_caption ).
lr_table->add_column( EXPORTING the_column = lr_table_column ).
* create the layout data of the text view
DATA lr_grid_data TYPE REF TO cl_wd_grid_data.
lr_grid_data = cl_wd_grid_data=>new_grid_data( lr_table ).
lr_table->set_layout_data( lr_grid_data ).
lr_container->add_child(
EXPORTING
the_child = lr_table ).
ENDIF.
ENDMETHOD.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.