cancel
Showing results for 
Search instead for 
Did you mean: 

Color a table row

Former Member
0 Kudos

Hello community!

I'm using a table in a view, and I'd like to color some rows depending on a condition value.

I've found some tips for coloring a row when using an ALV, but that's not my case.

How could I do that?

Thanks for any help 😃

Have a great day 😃

C.

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Below is the coding from WDDOINIT that I use for populating the table & attribute COLOUR with data.

method WDDOINIT .
  data: wd_node type ref to if_wd_context_node,
        lt_sflight type wd_this->elements_sflight,
        wa_sflight type wd_this->element_sflight.

  wd_node = wd_context->get_child_node( name = 'SFLIGHT' ).

*** Fetch the desired data from SFLIGHT
  
  select carrid
         connid
         fldate
         price from sflight into corresponding fields of table lt_sflight.
*** Am just trying to reduce the resultset so that it would be easier to see the output
  sort lt_sflight by price.
  delete adjacent duplicates from lt_sflight comparing price.

*** This is the main part. I loop through the data from SFLIGHT & check which rows have PRICE > 500
*** I assign different values to the COLOUR attribute when it is ( greater than 500 ) & ( less than or equal to 500 )
  loop at lt_sflight into wa_sflight.
    if wa_sflight-price > 500.
      wa_sflight-colour = '11'.
    else.
      wa_sflight-colour = '07'.
    endif.
    modify lt_sflight from wa_sflight transporting colour.
  endloop.

  wd_node->bind_table( new_items = lt_sflight ).
endmethod.

Answers (4)

Answers (4)

uday_gubbala2
Active Contributor
0 Kudos

So thats it! Now upon execution your table would show all rows which have PRICE > 500 in 1 colour & the rest in another.

If you would like to check the possible list of values which you can assign then you can check the value range of the domain WDUI_TABLE_CELL_DESIGN which is associated with the type of the same name. (i.e, WDUI_TABLE_CELL_DESIGN).

Regards,

Uday

Former Member
0 Kudos

Thanks all of you for your helpful answers!!

Regards,

C.

uday_gubbala2
Active Contributor
0 Kudos

Hi Cristina,

Suppose I am displaying the data from SFLIGHT in a table & I want all the rows with PRICE > 500 in one colour and the rest in another then you can proceed as follows:

I have a context node by name SFLIGHT & it has CARRID, CONNID, FLDATE & PRICE as its attributes. In addition to these 4 dictionary fields I have a 5th attribute under the same node by name COLOUR. This is of type: WDUI_TABLE_CELL_DESIGN. I would be using this for changing the table's row colour. I dont hev any special settings for my context node.

SFLIGHT node:

Cardinality: 0..n
Selection: 0..1

I design a table in my layout & am displaying only the 4 dictionary fields in the table. (i.e, while doing the binding for the table I uncheck the checkbox for COLOUR so that it wouldnt get displayed.) Now I go to each column and bind its "cellDesign" property with the context attribute COLOUR. (i.e, MAIN.SFLIGHT.COLOUR)

So now as how you would have understood while populating my table with values I would just have to fill the context attribute COLOUR with the right value to reach the desired solution.

Former Member
0 Kudos

Hi,

You have to loop at table columns and set the cell design fieldname like this

*  loop at lt_column into ls_column.
*
** bind the context attribute 'CELL_COLOR' as deisgn field for all of the columns, this will decide
** the color for totals column.

    CALL METHOD LS_COLUMN-r_column->SET_CELL_DESIGN_FIELDNAME
      EXPORTING
       VALUE = 'CELL_COLOR'.

Here CELL_COLOR is a table column ( it can be hidden ) and based on your logic you can populate the cell_color value.

CELL_COLOR is of type WDUI_TABLE_CELL_DESIGN.

Hope this helps

Regards

Manas Dua

Former Member
0 Kudos

Thanks for both of you 😃

I'm gonna try these out.

Regards,

C.

Former Member
0 Kudos

Hi,

Do you want to color the entire row or some cells.

Regards,

Lekha.

Former Member
0 Kudos

Hi!

I'd like to color the entire row.

Thanks 😃

Former Member
0 Kudos

Hi,

In this link -

-check Manoj's reply

they have used READ_ONLY to edit but you can use the same coding but replcae that READ_ONLY with the WDUI_TABLE_CELL_DESIGN type. Replace READ_ONLY as CELL_DESIGN.

Write the code in the WDODOMODIFY View and get the table reference.

In the LOOP.....

if....

cell_design = '01'.

else.

cell_design = '02'.

endif.

ie

LOOP AT lt_node INTO ls_node.
IF sy-tabix = lv_index.
ls_node-cell_design = '01'.
ELSE.
ls_node-cell_design = '02'.
ENDIF.
MODIFY lt_node INDEX sy-tabix FROM ls_node TRANSPORTING cell_design.

ENDLOOP.

Is this clear....

Regards,

Lekha.