WDA组件复用 ALV颜色设置 SALV_WD_TABLE
作者:互联网
WDA中ALV的颜色控制和REPORT开发中的ALV颜色设置类似,只是写法有些不同,同用需要在内表里加入控制颜色的字段,在处理数据的时候对它赋值就可以
首先在内表中添加控制颜色的字段
在初始化ALV的时候设置相应字段的属性
DATA: LT_COLUMNS TYPE SALV_WD_T_COLUMN_REF,
LS_COLUMNS TYPE SALV_WD_S_COLUMN_REF.
* define UI element
DATA: LC_INPUT TYPE REF TO CL_SALV_WD_UIE_INPUT_FIELD.
* define column header
DATA: LC_COLUMN_HEADER TYPE REF TO CL_SALV_WD_COLUMN_HEADER.
* set columns table
LT_COLUMNS = WD_THIS->ALV_CONFIG_TABLE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMNS( ).
LOOP AT LT_COLUMNS INTO LS_COLUMNS.
CASE LS_COLUMNS-ID.
WHEN 'ID'.
LS_COLUMNS-R_COLUMN->SET_CELL_DESIGN( CL_WD_ABSTR_MASTER_TABLE_COL=>E_CELL_DESIGN-POSITIVE ).
WHEN 'NAME'.
LS_COLUMNS-R_COLUMN->SET_CELL_DESIGN_FIELDNAME( 'CELL_BACKG' ).
WHEN 'PHONE'.
DATA LR_CELL_EDITOR TYPE REF TO CL_SALV_WD_UIE.
DATA LR_TEXT_VIEW TYPE REF TO CL_SALV_WD_UIE_TEXT_VIEW.
LR_CELL_EDITOR = LS_COLUMNS-R_COLUMN->GET_CELL_EDITOR( ).
IF LR_CELL_EDITOR->EDITOR = IF_SALV_WD_C_COLUMN_SETTINGS=>CELL_EDITOR_TEXT_VIEW.
LR_TEXT_VIEW ?= LR_CELL_EDITOR.
LR_TEXT_VIEW->SET_SEMANTIC_COLOR_FIELDNAME( 'TEXT_BACKG' ).
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
在处理数据的时候对相应控制颜色的字段赋值
DATA LO_ND_GT_ALV2 TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LT_GT_ALV2 TYPE WD_THIS->ELEMENTS_GT_ALV2.
DATA LS_GT_ALV2 LIKE LINE OF LT_GT_ALV2 .
LS_GT_ALV2-ID = '0000000010'.
LS_GT_ALV2-NAME = 'AFFILSC'.
LS_GT_ALV2-PHONE = '1544894651656'.
LS_GT_ALV2-CELL_BACKG = cl_wd_abstr_master_table_col=>e_cell_design-criticalvalue_medium.
APPEND LS_GT_ALV2 TO LT_GT_ALV2 .
CLEAR LS_GT_ALV2 .
LS_GT_ALV2-ID = '0000000020'.
LS_GT_ALV2-NAME = 'DEFFINE'.
LS_GT_ALV2-PHONE = '1544894651656'.
LS_GT_ALV2-TEXT_BACKG = cl_wd_text_view=>e_semantic_color-critical..
APPEND LS_GT_ALV2 TO LT_GT_ALV2 .
CLEAR LS_GT_ALV2 .
LS_GT_ALV2-ID = '0000000030'.
LS_GT_ALV2-NAME = 'CLOGNPD'.
LS_GT_ALV2-PHONE = '1544894651656'.
LS_GT_ALV2-COL_BACKG = cl_wd_abstr_master_table_col=>e_cell_design-group_level2.
APPEND LS_GT_ALV2 TO LT_GT_ALV2 .
* navigate from <CONTEXT> to <GT_ALV2> via lead selection
LO_ND_GT_ALV2 = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_GT_ALV2 ).
*
LO_ND_GT_ALV2->BIND_TABLE( NEW_ITEMS = LT_GT_ALV2 SET_INITIAL_ELEMENTS = ABAP_TRUE ).
效果:
标签:WDA,GT,ALV2,CELL,WD,LS,ALV,COLUMNS 来源: https://blog.csdn.net/qq_40977705/article/details/111504311