cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting all rows in ALV on a button click

Former Member
0 Kudos

Hi,

I have a dynamic ALV table. I also have a button 'Select All Rows'. On clicking the button I want all the rows in the ALV table selected. Similarly I want to deselect all the rows if I click another button 'Deselect All Rows'.

Is it possible to do this way? Is there a similar functionality already existing in ALV component?

Thanks & Regards,

Reena

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

In addition to setting the Table Selection to MULTI -

Create a Function on ALV ToolBar with a Button 'Select All'

When it is pressed, get all the element count of the node and set all to selected.

data lv_count type i

lv_count = Node->get_element_count( ).

Do lv_count times.

Node->Set_Selected( sy-index ).

Enddo.

Similarly create a button for 'Deselect All'

When it is pressed, clear the selection

Node->clear_selection( ).

russell_day2
Participant
0 Kudos

I have an application where I want to select everything initially.

I cannot get it to select the first row.

The demo program has a table populated from SCARR.

The entire code is in WDDOINIT:

method WDDOINIT .

data lo_cmp_usage type ref to if_wd_component_usage.

data: lr_node type ref to if_wd_context_node,

lr_scarr_alv type ref to iwci_salv_wd_table,

lr_model type ref to cl_salv_wd_config_table,

lr_table_settings type ref to if_salv_wd_table_settings,

lt_elements type wdr_context_element_set,

lr_element like line of lt_elements.

  • Create the component.

lo_cmp_usage = wd_this->wd_cpuse_alv_grid( ).

if lo_cmp_usage->has_active_component( ) is initial.

lo_cmp_usage->create_component( ).

endif.

  • Get a reference to the ALV component, then to the model.

lr_scarr_alv = wd_this->wd_cpifc_alv_grid( ).

lr_model = lr_scarr_alv->get_model( ).

lr_table_settings ?= lr_model.

  • Set selection mode to MULTI.

lr_table_settings->set_selection_mode( cl_wd_table=>e_selection_mode-multi_no_lead ).

  • Now select them all.

lr_node = wd_context->get_child_node( 'SCARR' ).

lt_elements = lr_node->get_elements( ).

loop at lt_elements into lr_element.

lr_element->set_selected( abap_true ).

endloop.

endmethod.

Where am I going wrong? Doesn't matter what I do to it, the first element is never selected.

Edited by: Russell Day on Jan 31, 2008 11:01 AM

Edited by: Russell Day on Jan 31, 2008 11:03 AM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

This feature is inbuilt in the ALV. You need to enable multiple selection in your ALV by using the method IF_SALV_WD_TABLE_SETTINGS~set_selection_mode. You can then see a toggle button for select/deselect all in the top left corner of your ALV grid.

Regards

Nithya

Former Member
0 Kudos

Hi Nithya,

I am already using IF_SALV_WD_TABLE_SETTINGS~set_selection_mode method to select multiple rows manually. But I do not get toggle button for select/deselect all rows.

I am passing if_hrasr00_sel_mode_constants=>multi as a parameter to IF_SALV_WD_TABLE_SETTINGS~set_selection_mode method.

Thanks & Regards,

Reena

Former Member
0 Kudos

Check if the constant you are passing has value '04'. You need to pass cl_wd_table=>e_selection_mode-multi.

Regards

Nithya

Former Member
0 Kudos

Hi Nithya,

It doesn't show select/deselect all rows button. set_selection_mode method is used to enable single selection or multiple selection of rows. But it does not provide a built in button as such on alv to select/deselect all rows.

The value of the parameter I am passing is 04.

Is there any other way to solve this problem?

Thanks & Regards,

Reena

Former Member

Hi,

I have solved the problem myself by calling set_selected() method of if_wd_context_node.

Regards,

Reena