Skip to Content
avatar image
Former Member

add check box column to the table

Hi,

I want to add a check box column in the table, so that the items in the table can be selected (multi-selection) by clicking the check box before each line item. How can I implement it?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 27, 2008 at 08:30 AM

    Hi, Vishal

    thanks a lot. but where should I put these code?

    Best regards

    Fan

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Fan,

      You can try do it in 2 ways: statically & dynamically.

      I will explain both of the ways to you. Suppose you have bound your table to a context node by name SFLIGHT. It contains CARRID, CONNID, FLDATE, PRICE & an attribute by name CHECK of type WDY_BOOLEAN.

      Static Method:

      When you right click on your table & say "Create Binding" you select the context node as SFLIGHT & then you get the option to specify the Cell editor of the various table columns. Now go to your column CHECK and select the cell editor as "Checkbox" & name of property to be bound as "Checked". Now this would result in the column CHECK being displayed as a checkbox to you. Also the checked/unchecked values go and get stored in the boolean attribute CHECK that you had created at context level.

      Dynamic Method:

      Whenever you are working with dynamic ui modification you need to put your coding inside the WDDOMODIFYVIEW method. You need to basically perform the below steps to realise your functionality:

      1) You need to first get the reference of the table element.

      2) You then use this reference to get the reference of the desired column by specifying the column index. 3) 3) You then create an object of type checkbox & then embed it within the cell editor of the table column

      Below is the coding from the method:

      method WDDOMODIFYVIEW .
        data: lr_table type ref to cl_wd_table,
              lr_column type ref to cl_wd_table_column,
              lr_check  type ref to cl_wd_checkbox.
      
        check first_time = abap_true.
      
        lr_table ?= view->get_element( id = 'TABLE' ).
      
        lr_column ?= lr_table->get_grouped_column( id = 'TABLE_CHECK' ).
      
        lr_check = cl_wd_checkbox=>new_checkbox( bind_checked = 'SFLIGHT.CHECK' ).
      
        lr_column->SET_TABLE_CELL_EDITOR( THE_TABLE_CELL_EDITOR = lr_check ).
      endmethod.

      Regards,

      Uday

  • avatar image
    Former Member
    Nov 27, 2008 at 09:46 AM

    Hi, everyone,

    thank you all for your help. I think I got the solution: no matter what, I have to first add a column in the table that I use for binding. I have also tried to add a new column in Table UI, but then I do not know how to bind the checkboxes in this column, because each checkbox should be related to each context element of the table.

    Because I used BAPI to get the table for binding and it is not quite efficient to change the table structure, so I want to ask:

    Is there any other way that we can do multiselection without pressing CTRL?

    Best Regards

    Fan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Fan,

      If I understand it correctly, the initial reason why you had put the check box was to enable multiple lead selection, if thats the case, Let me first make it clear that it is possible to lead select multipe table entries without using the CTRL button.

      The way to go about it is to do the coding in the onToggle event of the checkbox.

      In the same, you can get the complete table detail, loop at the table where the check box is checked.

      Find the index of the checked entry. and use the method

      lv_index is the value of the the index

      
      loop at +internal table+ into workarea.
           lv_index = sy-tabix.
           if workarea-checkbox = checked.
                 call method node_reference->set_selected
                   exporting
                     flag  = abap_true.
                     index = l_v_index.
           else.
                  call method node_reference->set_selected
                   exporting
                     flag  = abap_false.
                     index = l_v_index.
           endif.
      endloop.
      

      Edited by: Rajesh K Soman on Jan 6, 2009 9:45 AM

  • avatar image
    Former Member
    Nov 26, 2008 at 05:56 PM

    Hello,

    Just create a new column to the table. Right-click the table UI element, and so on... Then when you have the column there, just create a new UI element for it (normally they are type TextView, if you have created the table with the wizard), but instead of text view select checkbox. It is very easy and logical once you try it. (Of course you need to first create a suitable attribute (of type WDY_BOOLEAN) into your context node.)

    If your aim is to make the table rows selectable, you could achieve this also by changing the "selection mode" property of the UI element to "multi". Then you can select multiple rows from the table without creating a new checkbox column for it. You can choose a row in the table just by clicking the "box" in the table row.

    Regards,

    Karri

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 27, 2008 at 03:56 AM

    Hi,

    Here is the code to implement the checkbox in a column.

      DATA lo_column_settings TYPE REF TO if_salv_wd_column_settings.
      DATA lo_column          TYPE REF TO cl_salv_wd_column.
      DATA lo_column_hdr      TYPE REF TO cl_salv_wd_column_header.
      DATA lr_checkbox TYPE REF TO cl_salv_wd_uie_checkbox.
    
      lo_column = lo_column_settings->get_column( 'SELECTION' ).
      lo_column->set_h_align( cl_wd_table_column=>e_h_align-center ).
    *  lo_column->set_position( value = 2 ).
    *  lo_column->set_width( value = '75' ) .
      lo_column_hdr = lo_column->create_header( ).
      lo_column->set_fixed_position( cl_wd_abstr_table_column=>e_fixed_position-left ) .
    
      CREATE OBJECT lr_checkbox
        EXPORTING
          checked_fieldname = 'SELECTION'.
    
      lo_column->set_cell_editor( lr_checkbox ).
      lr_checkbox->set_enabled( value = abap_true ).
     * lr_checkbox->set_enabled_fieldname( value = 'STOKZ' ).
      

    Regards

    Vishal

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 27, 2008 at 08:29 AM

    Hi, Karri,

    thanks for your reply. Yes, the aim of adding a checkbox column is to select the row. I have already set the selection mode to "multi", but i am not quite satisfied with the end effect: the user has to press ctrl in order to do multiselection.

    There is a style that I have seen in some documentation: before each line item of table there is a checkbox, which is bigger than the normal ones and the user can check as many checkboxes as he wants.

    Do you have an idee how this is implemented?

    Thanks.

    Best Regards

    Fan

    Add comment
    10|10000 characters needed characters exceeded