cancel
Showing results for 
Search instead for 
Did you mean: 

Coloring a row in Table Control

Former Member
0 Kudos

Hi All,

I want to color a row of a table control based on some condition. Is this possible?

Thanks

Raghavendra

Accepted Solutions (0)

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Step-1: Add a new Attribute of type "WDY_UIE_LIBRARY_ENUM_TYPE" to the Context Node which is used to display the data on ALV. Lets name the Attribute as "CELL_COLOUR".

Step-2: Figure out the column (Column Variance in the below example) which has to be marked with a different colour based on its content. Assign the context attribute "CELL_COLOUR" to the "Cell Design Fieldname" attribute of the respective column. This can be done while setting Column attributes for each of the ALV Columns - as shown below:

  • Data declarations for ALV

DATA: lt_columns TYPE salv_wd_t_column_ref,

ls_column TYPE salv_wd_s_column_ref,

lo_column TYPE REF TO cl_salv_wd_column ,

lo_col_head TYPE REF TO cl_salv_wd_column_header ,

lo_ref_cmp_usage TYPE REF TO if_wd_component_usage,

lo_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table ,

lo_value TYPE REF TO cl_salv_wd_config_table.

  • Get reference to the Component usage of the ALV.

lo_ref_cmp_usage = wd_this->wd_cpuse_alv( ).

IF lo_ref_cmp_usage->has_active_component( ) IS INITIAL.

lo_ref_cmp_usage->create_component( ).

ENDIF.

  • Get reference to the Interface controller of the ALV.

lo_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).

lo_value = lo_ref_interfacecontroller->get_model( ).

wd_this->m_alv_model = lo_value.

  • Get the Columns of the ALV

CALL METHOD lo_value->if_salv_wd_column_settings~get_columns

RECEIVING

value = lt_columns.

  • Get reference to each column and set the column heading.

LOOP AT lt_columns INTO ls_column.

lo_column = ls_column-r_column.

CASE ls_column-id.

WHEN 'VARIANCE'.

lo_col_head = lo_column->get_header( ) .

lo_col_head->set_ddic_binding_field( ).

DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.

CREATE OBJECT lr_input_field EXPORTING value_fieldname = 'VARIANCE'.

lo_column->set_cell_editor( lr_input_field ).

lo_column->set_cell_design_fieldname( value = 'CELL_COLOR' ).

WHEN 'CELL_COLOR'.

CALL METHOD lo_column->set_visible(

EXPORTING

value = '00'

).

ENDCASE.

ENDLOOP.

Step-3: While populating the data into the Context which is bound to the ALV - Do the following based on the content of "VARIANCE" Field to set its colour accordingly -

  • VARIANCE

ls_final-variance = ls_final-current_amount - ls_final-ses_forecast.

IF ls_final-variance < 0.

ls_final-cell_color = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-BADVALUE_DARK.

ELSE.

ls_final-cell_color = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-STANDARD.

ENDIF.

Edited by: Uday on Sep 15, 2008 1:05 PM

Former Member
0 Kudos

Hi,

Yes this is possible.

Take an attribute 'CELL_DESIGN' of type WDUI_TABLE_CELL_DESIGN.

populate this value with color and assign this attribute to cell which you want to give color.check the below code.

Here i assigned to only one column if you want to add the same color to entire row then use get_columns method and then apply cell_design to all the columns.

data:obj_table type ref to cl_wd_table,
      lr_column type ref to cl_wd_table_column.

obj_table ?= view->get_element( 'TABLE1' ).
obj_table->set_visible_row_count( value = 50  ).

lr_column = obj_table->get_column(
               id         = 'TABLE1_PRICE'
*              INDEX      = INDEX
                 ).

loop at it_flights into ls_flights .
 if ls_flights-price = '185.00'.
    ls_flights-readonly = abap_true.
 ls_flights-cell_design =
cl_wd_table_column=>e_cell_design-badvalue_dark.
else.
 ls_flights-cell_design =
cl_wd_table_column=>e_cell_design-goodvalue_medium.
endif.
 append ls_flights to it_final.
endloop.

lr_column->bind_cell_design( path = 'NODE_name.CELL_DESIGN'  ).

Thanks,

Suman

Former Member
0 Kudos

Hello Raghavendra,

the cells can be colored by setting the property cellDesign of a TableColumn.

Bind the property cellDesign to a context attribute of type WDUI_TABLE_CELL_DESIGN containing the value for the color.

For possible values for the color please check [http://help.sap.com/saphelp_nw70/helpdata/en/45/0ef14d9d942462e10000000a1553f7/frameset.htm|http://help.sap.com/saphelp_nw70/helpdata/en/45/0ef14d9d942462e10000000a1553f7/frameset.htm]

Kind regards,

Silke