cancel
Showing results for 
Search instead for 
Did you mean: 

how to bind dynamic checkbox to a table

Former Member
0 Kudos

Hi,

I have a table that holds many fields. I put these fields on the screen dynamically.

I would like to bind a checkbox to select a field row.

I tried to bind the checkbox to the table but with no success. I keep getting the binding to the first element.

Does anyone has an example?

Thanks,

Itay

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Thanks for the help.

I solved the issue.

The multi pane is nice but did not help since it is one container under the other (except of this it is what I needed).

Finally, I created a dynamic node structure and I assign it nodes as I build it and with another action on the checkbox, once clicked I mark the original item that I need.

Regards,

Itay

Former Member
0 Kudos

Hi Itay,

if its table you are binding then u must use a the table UI element. At times the dynamic programing can be little cumbersome, what i will suggest it, try generating UI elements in the View using the

"Create Form From" functionality. For the "Attribute" in question choose Check Box as UI element.

When u select Check Box, bind property CHANGES to..specific TYPE " example "as Text" "as Key" etc cant recall exactly what will it read for Check Box as of now, but when you do this you will find the TYPE , When using the dynamic creation you need to bind Value of this TYPE.

Greetings

Prashant

Former Member
0 Kudos

Hi P,

what you are suggesting is the regular simple way and it is not what I am looking for. It does not work for me.

I have a table that holds few fields.

I need to present all the information of one row in a box and put 4 or 5 of them in one single row.

Thanks,

Itay

Former Member
0 Kudos

If thats the case then you need to first read all the table data to one internal table,

then loop thru this table and start binding the row items one by one to you dynamically created check box, since you are looping at next iteration you will have new row items that get binded!!

may be if you put source , i can be of greater help

Greetings

Prashant

Former Member
0 Kudos

Hi P,

here is my code:


  LOOP AT lt_available_items ASSIGNING <item>.

    ADD 1 TO lv_col.
    IF lv_col > lv_cell_per_col.
      lv_col = 1.
      ADD 1 TO lv_row.
      lv_new_line = 'X'.
    ENDIF.

*   Add dynamic group
    CONCATENATE 'GROUP_' lv_col '_' lv_row INTO lv_str.

    lr_new_group = cl_wd_group=>new_group( id = lv_str view = view design = '02' ).
    IF lv_new_line = 'X'.
      CLEAR lv_new_line.
      cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_new_group ).
    ELSE.
      cl_wd_matrix_data=>new_matrix_data( element = lr_new_group ).
    ENDIF.
    lr_new_group->set_width( '230' ).
    cl_wd_matrix_layout=>new_matrix_layout( container = lr_new_group ).
    lr_group->add_child( lr_new_group ).

*   Left side container
    CONCATENATE 'CONT_L_' lv_col '_' lv_row INTO lv_str.
    lr_new_container = cl_wd_transparent_container=>new_transparent_container(
          id = lv_str view = view ).
    cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_new_container ).
    cl_wd_matrix_layout=>new_matrix_layout( container = lr_new_container ).
    lr_new_group->add_child( lr_new_container ).

*   Add checkbox
    CONCATENATE 'CHK_' lv_col '_' lv_row INTO lv_str.
    lr_checkbox = cl_wd_checkbox=>new_checkbox( view   = view
                                                id     = lv_str ).
    lr_matrix_head = cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_checkbox ).
    lr_checkbox->set_layout_data( lr_matrix_head ).
    lr_checkbox->bind_checked( 'AVAILBLE_ITEMS.SELECTED' ).
    lr_new_container->add_child( lr_checkbox ).

...
endloop.

my node is AVAILABLE_ITEMS and it has the attributes: SELECTED, MATNR, MAKTX...

thanks,

Itay

former_member402443
Contributor
0 Kudos

Hi,

Check this WDA Component - demodynamic in your system.

Hopes this will helps you.

Regard

Manoj Kumar

uday_gubbala2
Active Contributor
0 Kudos

Hi Itay,

I would first try to say as to what understood about your intended layout. Depending up on the number of elements you have in your node AVAILABLE_ITEMS you want to dynamically create each row for them & display a checkbox beside each so that they can be selected by the user. So suppose if the table has 10 rows then you want to create 10 boxes and embed the details as TextViews inside each of them. Right?

If this is the case then I would suggest you to go for the MultiPane ui element. Using this element your scenario would get very simplified. It would take care of the dynamic ui elements generation & you wouldn't need to write even a single bit of code in your WDDOMODIFYVIEW method. You can go through my [article|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/106209dd-edc9-2b10-b4a5-911ef18aac89] for further details about how you can use the MultiPane ui element.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Itay,

I will try explain as to how you can achieve the desired functionality using the MultiPane for your desired layout.

1) Create an boolean attribute say CHECKED (of type WDY_BOOLEAN) under the node AVAILABLE_ITEMS. This attribute would be used later for binding to your checkbox to determine which row (i.e, in your case group of data) has been selected by the user.

2) Place an MultiPane ui element (say mpane) in your view

3) Bind the dataSource property of the element to AVAILABLE_ITEMS.

(So suppose if you have embedded a TextView under this multipane & if the node (AVAILABLE_ITEMS) has 10 rows of data then the multipane would now dynamically create 10 TextViews for you. I hope that you have got this concept cleared.)

Since you can only embed 1 element within the MultiPane we first embed a TransparentContainer (say TC1) within this MultiPane element. Now within TC1 we can embed as many elements as we wish.

So now within TC1 embed a CheckBox & another Group ui element (say GR1).

Now right click on GR1 & say, "Create Container Form". Now select your context node AVAILABLE_ITEMS & select the cell editors to be displayed as TextViews.

That't it. Your requirement has been accomplished! Try playing around with the layout properties so that you get the ui elements displayed in the desired position and order.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Itay,

There is however 1 performance issue here with this approach. Suppose your node AVAILABLE_ITEMS has 1000 rows of data then the MultiPane would replicate its embedded elements 1000 times and display them all within the same view. So this can get very time consuming. You can set a few other properties of the MultiPane element to rectify this.

You can enter a value in rowCount to specify the number of rows of data that you want to be visible at a given point of time in the view.So suppose you give the value as 4 then at any point of time your view would only display 4 boxes of information from AVAILABLE_ITEMS. But you wouldnt be able to see the rest of the information so just checkmark the "footerVisible" property of the MultiPane. You would then get a footer similar to a table and you can use it to scroll through your rows of data.

Hope that this would help resolve your problem.

Regards,

Uday

Former Member
0 Kudos

Hi Italy,

the problem is

lr_checkbox->bind_checked( 'AVAILBLE_ITEMS.SELECTED' ).

this will always bind the element at the lead select from your context thus you will always get the SAME element.

Well if your intention is to display CHECK BOX for the content from the context and then provide user with

selecet & delselect functionality. You might have to re-think. You might as well create a TABLE of IF_WD_CONTEXT_ELEMENT,

read your entire CONTEXT in that table. Essentially the CheckBox Label would form your MAKTX and selected would finally

end up being binded to CHECK BOX.

Greetings

Prashant