Alvgrid learning notes -- Add button on toolbar

Source: Internet
Author: User

The previous two days I learned about the dobule Click Event of algrid and how to add a Custom button to the toolbar of alvgrid.

Add a Custom button on the alvgrid toolbar, which is similar to adding a dobule click event. Specifically, a custom class is used to implement the toolbar event of alvgrid, add the Custom button to the toolbar event, and then implement

User_command is used to process subsequent actions after a button is clicked.

First, let's take a look at the toolbar event of alvgrid. The toolbar event is mainly used to add custom items on the alvgrid toolbar. Select class/interface in repository browser, and then select

User_command. Expand events to display all the events that we can use. Double-click "toolbar" and select the paremeters button. We will open the toolbar event with the e_object and e_interactive parameters. Next, let's take a look at the user_command event. The user_command event is mainly used to process user-defined commands. This event carries an e_ucomm parameter.

The following code shows how to add a Custom button to the alvgrid toolbar. In this instance, we will add a Custom button on the alvgrid toolbar. Select a row in the alvgrid record and double-click the Custom button to go to another screen (No: 0120) and display the detailed data on the screen. The main code is as follows:

1. Define a class that contains two methods:

Handler_toolbar corresponds to the alvgrid toolbar event,

Handler_user_command corresponds to the user_command event of alvgrid. The Code is as follows:

 

Class grid_event_receiver definition.
Public section.
Methods:
Handler_toolbar for event Toolbar of cl_gui_alv_grid
Importing e_object e_interactive,
Handler_user_command for event user_command of cl_gui_alv_grid
Importing e_ucomm.
Endclass. "event_receiver Definition

2. Implement the methods defined in the class. In the handler_toolbar event, add Stb_button, and Stb_button

Function,  

Values are assigned to attributes such as quickinfo and text. The handler_user_command event is mainly used to process the actions after a button is clicked. The Code is as follows:

 

Class grid_event_receiver implementation.
Method handler_toolbar.
Data: ls_toolbar type stb_button.
Clear ls_toolbar.
Move 'bookings 'to ls_toolbar-function.
* Append icon to Show Booking table
Move icon_employee to ls_toolbar-icon.
Move 'show bookings '(111) to ls_toolbar-quickinfo.
Move 'detail' (112) to ls_toolbar-text.
Move ''To ls_toolbar-disabled.
Append ls_toolbar to e_object-> mt_toolbar.
Endmethod. "handler_toolbar

Method handler_user_command.
Data: lt_rows type lvc_t_row.
Case e_ucomm.
When 'bookings '. "click the button
Call method grid1-> get_selected_rows
Importing
Et_index_rows = lt_rows.
Call method cl_gui_cfw => flush.
Perform show_booking tables lt_rows.
Call screen 120 starting at 10 5. "Call another screen 0120
Endcase.
Endmethod. "handler_user_command
Endclass. "event_receiver

3. register the event in alvgrid. The method is similar to registering a double click event. Note that you must use the set_toolbar_interactive method of alvgrid to register a toolbar event. The Code is as follows:

 

Create object event_receiver.
Set handler event_receiver-> handler_toolbar for grid1.
Set handler event_receiver-> handler_user_command for grid1.
Call method grid1-> set_toolbar_interactive.
Call method cl_gui_cfw => flush.

Now, you have learned how to add a Custom button to the alvgrid toolbar. Someone may ask, in the handler_user_command event, the detailed data is not displayed on screen 0120. This is simple. We only call the screen with no 0120 in handler_user_command. After the screen is called, The PBo event of the screen will be executed, the task of displaying detailed data is implemented in the module of PBO. Similarly, disabling the screen is implemented in the module of Pai.

Today we are here. What will we learn tomorrow? Let's talk about it later! Partition _ Partition ︿_︿

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.