cancel
Showing results for 
Search instead for 
Did you mean: 

Select All /Deselect All toggle of Table

Former Member
0 Kudos

Hi,

anyone knows how to implement the select all/ deselect all toggle of a normal table? or is it possible to do so?

Best Regards

Fan

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Fan,

Selecting all rows of a table involves getting the count of total number of lines in your table. You then loop the same number of times & within the loop you use the set_selected method of if_wd_context_node to have the line as selected.

Below is the coding to select all the rows of a table:

METHOD onactionselect_all_rows.
  DATA: wd_node TYPE REF TO if_wd_context_node,
        line_count TYPE i,
        lt_kna1_value TYPE ig_componentcontroller=>elements_node1,
        lt_kna1_element TYPE wdr_context_element_set.

  wd_node = wd_context->get_child_node( name = 'NODE1' ).

  CALL METHOD wd_node->get_element_count
    RECEIVING
      count = line_count.
  DO line_count TIMES.
    wd_node->set_selected( index = sy-index ).
  ENDDO.
ENDMETHOD.

Similarly the coding for de-selecting all rows of the table is as shown below:

METHOD onactiondeselect_all_rows .
  DATA: wd_node TYPE REF TO if_wd_context_node,
        lines_count TYPE i VALUE 0.

  wd_node = wd_context->get_child_node( name = 'NODE1' ).
  CALL METHOD wd_node->get_element_count
    RECEIVING
      count = lines_count.
  DO lines_count TIMES.
    wd_node->set_selected( flag  = ''
                           index = sy-index ).
  ENDDO.
ENDMETHOD.

Regards,

Uday

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

thank you all for your help:-)

I have used the code of Uday. All your answers have helped me to solve the problem.

Best Regards

Fan

vishalc_kava
Explorer
0 Kudos

Hello Fan,

You can implement select all and deselect all functionality on the normal table.

For this create a context node for that particular view with attribute of type WDUI_TSMODE, bind this attribute with Table property 'selectionmode'

Create two button in the toolbar of the table 'selectall' & 'deselectall' on the actions of these buttons set the value of the attribute to

04 for select all and


*   set single attribute
  lv_selmode = 08.
  lo_el_selection->set_attribute(
    EXPORTING
      name =  `SELMODE`
      value = lv_selmode ).

06 for deselect all


  lv_selmode = 06.
  lo_el_selection->set_attribute(
    EXPORTING
      name =  `SELMODE`
      value = lv_selmode ).

and data source bound with the UI Element Table should have cardinality 0..n and selection 0..n

Regards

Vishal

uday_gubbala2
Active Contributor
0 Kudos

Hi Vishal,

Your coding does only set the property of the table but it doesnt select/deselect any rows. Fan wanted all his rows to automatically get selected when the user presses on the button. Your coding would only enable the table to be selected manually by the user. Hope you understood what I meant to say.

Regards,

Uday

vishalc_kava
Explorer
0 Kudos

Hello Uday,

I doubted the same thing that it will simply change the selection mode, but I simulated the same thing and it worked fine after which I posted my Idea for this thread.

Regards

Vishal

vishalc_kava
Explorer
0 Kudos

>

> Hello Fan,

>

> You can implement select all and deselect all functionality on the normal table.

> For this create a context node for that particular view with attribute of type WDUI_TSMODE, bind this attribute with Table property 'selectionmode'

>

> Create two button in the toolbar of the table 'selectall' & 'deselectall' on the actions of these buttons set the value of the attribute to

> 04 for select all and

>


> *   set single attribute
>   lv_selmode = 08.
>   lo_el_selection->set_attribute(
>     EXPORTING
>       name =  `SELMODE`
>       value = lv_selmode ).
> 

> 06 for deselect all

>


>   lv_selmode = 06.
>   lo_el_selection->set_attribute(
>     EXPORTING
>       name =  `SELMODE`
>       value = lv_selmode ).
> 

>

> and data source bound with the UI Element Table should have cardinality 0..n and selection 0..n

>

> Regards

> Vishal

Hello Fan,

My previous solution could create problem, if after de selecting the selection mode property of the table would become none and than user will not be able to select any rows.

Revisied solution could be


DATA lo_nd_wip TYPE REF TO if_wd_context_node.
  DATA lo_el_wip TYPE REF TO if_wd_context_element.
  DATA lt_el_wip_set TYPE wdr_context_element_set.

  lo_nd_wip = wd_context->get_child_node( name = wd_this->wdctx_wip ).

  CHECK lo_nd_wip IS NOT INITIAL.
  lt_el_wip_set = lo_nd_wip->get_elements( ).

  case <ACTION>.
    WHEN 'SELALL_BTN'.  "In the action of select all button
      LOOP AT lt_el_wip_set INTO lo_el_wip.
        lo_el_wip->set_selected( abap_true ).
      ENDLOOP.
    WHEN 'DESELALL_BTN'. "In the action of deselect all button
      lo_nd_wip->clear_selection( ).
      lo_nd_wip->set_lead_selection_index( lo_nd_wip->no_selection ).
  endcase.

Other solution enhnacement pack1 will have standard functionality for select all and deselect all.

Vishal

Former Member
0 Kudos

Hi,

In SP14, framework provides default toggle button to select all and deselect all rows. Otherwise you will need create own buttons and do the coding for selecting and deselecting the rows.

Regards

Rohit Chowdhary