on 04-03-2008 10:25 AM
I have a web dynpro ALV table, and the users can select mulitple entries in it.
Is there something like a built-in Select-All / Deselect-All functionality somewhere?
Hi Danies,
There is no inbuild functionality for doing a select all or de-select all. But this can be achieved by creating our custom functions.
When defining the configuration model of ALV, Do the following.
Assume that we get the model of our ALV into lo_empl_list.
lo_empl_list = lo_ref_interfacecontroller->get_model( ).
DATA:
* Generate an object for self defined functions
lo_self_functions TYPE REF TO if_salv_wd_function_settings,
* Generate an object for button 'Select All'
lo_button_sel_all TYPE REF TO cl_salv_wd_fe_button,
* Generate an object for button 'Deselect all'
lo_button_desel_all TYPE REF TO cl_salv_wd_fe_button,
*-----------------------------------------------
* Set Self-defined functions
*-----------------------------------------------
* 'Select all' Button
lo_self_functions ?= lo_empl_list.
lo_self_function = lo_self_functions->create_function( 'SELECTALL' ).
CREATE OBJECT lo_button_sel_all.
CLEAR l_text.
l_text = 'Select All'
lo_button_sel_all->set_text( l_text ).
lo_button_sel_all->set_image_source( 'ICON_SELECT_ALL' ).
lo_button_sel_all->set_image_first( /rio/zcl_constants=>c_true ).
lo_self_function->set_editor( lo_button_sel_all ).
* 'Deselect all' Button
lo_self_function = lo_self_functions->create_function( 'DESELECTALL' ).
CREATE OBJECT lo_button_desel_all.
CLEAR l_text.
l_text = 'Deselect all'
lo_button_desel_all->set_text( l_text ).
lo_button_desel_all->set_image_source( 'ICON_DESELECT_ALL' ).
lo_button_desel_all->set_image_first( /rio/zcl_constants=>c_true ).
lo_self_function->set_editor( lo_button_desel_all ).
Implement the event handler for ON_FUNCTION of ALV and in the method, do the following.
*--------------------------------------------------------------------*
* Reference to nodes
*--------------------------------------------------------------------*
DATA:
* Reference to employee list
lo_node_empl_list_data TYPE REF TO if_wd_context_node,
*--------------------------------------------------------------------*
* Local tables (lt_)
*--------------------------------------------------------------------*
lt_empl_list_data_ref TYPE wdr_context_element_set,
*--------------------------------------------------------------------*
* Local Structures (ls_)
*--------------------------------------------------------------------*
* Selected employee
ls_empl_list_data_ref TYPE REF TO if_wd_context_element, "#EC NEEDED
*--------------------------------------------------------------------*
* Local variables (l_)
*--------------------------------------------------------------------*
* Index
l_index TYPE i.
*----------------------------Begin of main processing----------------*
*---------------------------------------------------------------
* Get all the employees
*---------------------------------------------------------------
* navigate from <CONTEXT> to <EMPL_LIST_DATA> via lead selection
lo_node_empl_list_data = wd_context->get_child_node( name = if_employee_selection=>wdctx_empl_list_data ).
* @TODO handle not set lead selection
IF ( lo_node_empl_list_data IS INITIAL ).
EXIT.
ENDIF.
* Get reference to selected employees
CALL METHOD lo_node_empl_list_data->get_elements
RECEIVING
set = lt_empl_list_data_ref.
*-------------------------------------------------------
* Based on the function selected, set the selection
*-------------------------------------------------------
CASE r_param->id.
WHEN 'SELECTALL'.
CLEAR ls_empl_list_data_ref.
* Set all the records as selected
LOOP AT lt_empl_list_data_ref INTO ls_empl_list_data_ref.
l_index = sy-tabix.
CALL METHOD lo_node_empl_list_data->set_selected
EXPORTING
flag = abap_true
index = l_index.
ENDLOOP.
WHEN 'DESELECTALL'.
* Clear the selection and set the clear lead selection also.
CALL METHOD lo_node_empl_list_data->clear_selection.
CALL METHOD lo_node_empl_list_data->set_lead_selection_index
EXPORTING
index = 0.
WHEN OTHERS.
EXIT.
ENDCASE.
Hope this helps,
Regards,
Sravan Varagani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok Daniel, this is the code to have a checkbox editable in the ALV component with 2 buttons in the toolbar, select all & deselect all.
Put this code in the WDDOINIT method
DATA:
lo_cmp_usage TYPE REF TO if_wd_component_usage,
lo_interface TYPE REF TO iwci_salv_wd_table,
lo_alv_table TYPE REF TO cl_salv_wd_config_table,
lo_alv_col TYPE REF TO cl_salv_wd_column,
lo_alv_col_h TYPE REF TO cl_salv_wd_column_header,
lo_checkbox TYPE REF TO cl_salv_wd_uie_checkbox,
lo_function TYPE REF TO cl_salv_wd_function,
lo_button TYPE REF TO cl_salv_wd_fe_button.
* Create the used component
lo_cmp_usage = wd_this->wd_cpuse_usage_alv_1( ).
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.
* Get a reference to the interface controller of the ALV component
lo_interface = wd_this->wd_cpifc_usage_alv_1( ).
lo_alv_table = lo_interface->get_model( ).
* Change column UI element for checkbox
CREATE OBJECT lo_checkbox
EXPORTING
checked_fieldname = 'PROCESS'.
lo_checkbox->set_enabled( abap_true ).
lo_alv_col = lo_alv_table->if_salv_wd_column_settings~get_column( 'PROCESS' ).
lo_alv_col->set_cell_editor( lo_checkbox ).
lo_alv_col_h = lo_alv_col->get_header( ).
lo_alv_col_h->set_text( 'chk' ).
* Make ALV editable
lo_alv_table->if_salv_wd_table_settings~set_read_only( abap_false ).
* Add toolbar button to select items
CREATE OBJECT lo_button.
lo_button->set_tooltip( 'Select All' ).
lo_button->set_image_source( '@4B@' ).
lo_function = lo_alv_table->if_salv_wd_function_settings~create_function( 'SELECT_ALL' ).
lo_function->set_editor( lo_button ).
* Add toolbar button to deselect items
CREATE OBJECT lo_button.
lo_button->set_tooltip( 'Deselect All' ).
lo_button->set_image_source( '@4D@' ).
lo_function = lo_alv_table->if_salv_wd_function_settings~create_function( 'DESELECT_ALL' ).
lo_function->set_editor( lo_button ).
Now create an event handler in the component controller for the event on_function of the select option component usage
DATA lr_node TYPE REF TO if_wd_context_node.
DATA lt_elements TYPE wdr_context_element_set.
FIELD-SYMBOLS <lf_element> TYPE REF TO if_wd_context_element.
lr_node = wd_context->get_child_node( 'ARTICLES' ).
lt_elements = lr_node->get_elements( ).
CASE r_param->id.
WHEN 'SELECT_ALL'.
LOOP AT lt_elements ASSIGNING <lf_element>.
<lf_element>->set_attribute( name = 'PROCESS'
value = abap_true ).
ENDLOOP.
WHEN 'DESELECT_ALL'.
LOOP AT lt_elements ASSIGNING <lf_element>.
<lf_element>->set_attribute( name = 'PROCESS'
value = abap_false ).
ENDLOOP.
ENDCASE.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sravan
Solved it ....
Thanks and Regards
Karthick
Edited by: Karthick Gopi on Apr 24, 2008 4:38 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.