About ALV grid color

Source: Internet
Author: User
ALV colors are divided into row colors, column colors, and cell colors. 1. the color of a row must be added to the inner table to be displayed with color information, such as color (4) type C. ITAB-COLOR = 'c700 '. in addition, you must set the display color based on the FM or class method.
  • FM: LS_LAYOUT-INFO_FIELDNAME = 'color '.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'    EXPORTING      IS_LAYOUT   = LS_LAYOUT      IT_FIELDCAT = LT_FIELDCAT    TABLES      T_OUTTAB    = ITAB.
  • Class: SLA-INFO_FNAME = 'color '. call method go_grid-> export exporting is_variant = gs_variant I _save = 'A' is _ layout = slachanging it_outtab = itab [] conditions = gt_fieldcat [] conditions tions Limit = 1 program_error = 2 conditions = 3 others = 4.
2. Set the color of the column fieldcat, such as: TMP_FIELDCAT-EMPHASIZE = 'c500 '. "column color
3. the cell color needs to add a field cellcolors type lvc_t_scol in the inner table to be displayed. ls_cellcolor-color-col = '5 '. ls_cellcolor-color-int = '1 '. ls_cellcolor-color-inv = '1 '. append ls_cellcolor to list-cellcolors. append list.
 
Example:
REPORT  Z_BARRY_ALV_CL_COLOR2                   .
TYPES: BEGIN OF ilist_s ,      name1(10),      name2(10),      name3(10), END OF ilist_s.DATA: ilist TYPE STANDARD TABLE OF ilist_s  WITH HEADER LINE .
DATA: BEGIN OF list OCCURS 0.        INCLUDE STRUCTURE ilist .DATA: rowcolor(4) TYPE c ,      cellcolors TYPE lvc_t_scol ,      cellstyles TYPE lvc_t_styl ,      celltext   TYPE alv_t_dtv .DATA: END OF list.
DATA: ok_code LIKE sy-ucomm.DATA: l_valid(1) TYPE c.DATA: go_grid             TYPE REF TO cl_gui_alv_grid.
DATA: gt_fieldcat TYPE lvc_t_fcat,      gs_fieldcat TYPE lvc_s_fcat,      sla         TYPE lvc_s_layo.DATA: ls_fieldcat TYPE lvc_s_fcat.DATA ls_style TYPE lvc_s_styl .DATA ls_cellcolor TYPE lvc_s_scol .DATA ls_celltext     TYPE alv_s_dtv .
*---------------------------------------------------------------------**       CLASS lcl_event_receiver DEFINITION*---------------------------------------------------------------------***---------------------------------------------------------------------*CLASS lcl_event_receiver DEFINITION.  PUBLIC SECTION.    METHODS handle_button_click      FOR EVENT button_click OF cl_gui_alv_grid      IMPORTING es_col_id                es_row_no.ENDCLASS.                    "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------**       CLASS lcl_event_receiver IMPLEMENTATION*---------------------------------------------------------------------**       ........                                                      **---------------------------------------------------------------------*CLASS lcl_event_receiver IMPLEMENTATION.  METHOD handle_button_click.    PERFORM test USING es_col_id                       es_row_no.  ENDMETHOD.                                                "handle_f4ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
DATA: event_receiver TYPE REF TO lcl_event_receiver.DATA: ii TYPE i .
START-OF-SELECTION.
  CLEAR ls_fieldcat.  ls_fieldcat-fieldname     = 'NAME1'.  ls_fieldcat-scrtext_l     = 'NAME1'.  APPEND ls_fieldcat TO  gt_fieldcat.  CLEAR ls_fieldcat.  ls_fieldcat-fieldname     = 'NAME2'.  ls_fieldcat-scrtext_l     = 'NAME2'.*    ls_fieldcat-emphasize = 'C610'.  APPEND ls_fieldcat TO  gt_fieldcat.  CLEAR ls_fieldcat.  ls_fieldcat-fieldname     = 'NAME3'.  ls_fieldcat-scrtext_l     = 'NAME3'.  APPEND ls_fieldcat TO  gt_fieldcat.
  list-name1 = 'A'.  list-name2 = 'ARE'.  ls_cellcolor-fname = 'NAME1' .  ls_cellcolor-color-col = '5' .  ls_cellcolor-color-int = '1' .  ls_cellcolor-color-inv = '1' .  APPEND ls_cellcolor TO list-cellcolors .  APPEND list.  list-name1 = 'AA'.  list-name2 = 'BB'.  ls_cellcolor-fname = 'NAME2' .  ls_cellcolor-color-col = '3' .  ls_cellcolor-color-int = '1' .  ls_cellcolor-color-inv = '1' .  APPEND ls_cellcolor TO list-cellcolors .  APPEND list.  list-name1 = 'HOW'.  list-name2 = 'ARE'.  list-rowcolor = 'C410'.  ls_style-fieldname = 'NAME3' .  ls_style-style = cl_gui_alv_grid=>mc_style_button .*  ls_style-style = cl_gui_alv_grid=>MC_STYLE_HOTSPOT.  APPEND ls_style TO list-cellstyles .  ls_celltext-buttoncell = 'TEST'.  APPEND ls_celltext TO list-celltext.  APPEND list.
  sla-stylefname = 'CELLSTYLES'.  sla-ctab_fname = 'CELLCOLORS'.  sla-info_fname = 'ROWCOLOR'.
  WRITE 'a'.  CREATE OBJECT go_grid        EXPORTING          i_parent = cl_gui_container=>screen0.
  CREATE OBJECT event_receiver.  SET HANDLER event_receiver->handle_button_click FOR go_grid.
  CALL METHOD go_grid->set_table_for_first_display    EXPORTING*      is_variant                    = gs_variant      i_save                        = 'A'      is_layout                     = sla    CHANGING      it_outtab                     = list[]      it_fieldcatalog               = gt_fieldcat[]    EXCEPTIONS      invalid_parameter_combination = 1      program_error                 = 2      too_many_lines                = 3      OTHERS                        = 4.*&---------------------------------------------------------------------**&      Form  test*&---------------------------------------------------------------------*FORM test  USING    p_es_col_id TYPE lvc_s_col                    p_es_row_no TYPE lvc_s_roid.  MESSAGE i899(fi) WITH p_es_col_id-fieldname p_es_row_no-row_id .ENDFORM.                    " test

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.