cancel
Showing results for 
Search instead for 
Did you mean: 

dynamically color table rows based on condition

Former Member
0 Kudos

Hi,

i tried searching on the above topic in the forum but couldn't locate the one that meets my scenario. I am reading data from a BAPI and the table (Not ALV) is directly attached to the BAPI context nodes (Child nodes). So the data is automatically populated to the table. now i want some rows to be highlighted with some color basing on certain condition. Can you please help wiht the code hints on how to do that?

i wrote the below code but it is failing at the highlighted line saying "Access via 'NULL' object reference not possible";

can anyone please help?

  • wd_table_column ?= view->get_element( 'T_WBSLIST_WBS_ELEMENT' ).

*

  • structdescr ?= cl_abap_typedescr=>describe_by_data( e_wbs_element_table ).

*

  • LOOP AT structdescr->components INTO component.

  • IF component-name = 'WBS_ELEMENT'.

*

      • wd_standard_cell->set_cell_design( cl_wd_abstr_master_table_col=>e_cell_design-badvalue_medium ).**

  • ENDIF.

*

  • wd_table_column->add_cell_variant( wd_standard_cell ).

  • ENDLOOP.

Thanks

Aditya

Edited by: Aditya Atluri on Nov 5, 2010 9:37 PM

Accepted Solutions (0)

Answers (3)

Answers (3)

Sharathmg
Active Contributor
0 Kudos

It is better to adress the requirement using the context attributes instead of settign the table view.

Declare an attribute as part of the node data which is boudn to the table. Ex: if node "details" is bound to table, create an attribute cell_design in that node. Then, while loading the data, loop the internal table which holds the data to be boudn to the table. Loop through the internal table and set the cell design attribute as per your requirement for certain rows and for the rest of rows set it as "standard". Check the data element "WDUI_TEXTVIEW_SEM_COL".

Bind the attribute to the semantic color property of the table or all the text editors in the table.

Regards,

Sharath M G

Former Member
0 Kudos

Jayanthi, Sharath,

Last night i have coded it the same way and finally was abel to highlight the cell. But thank you for your responses. But this only looked as a workaround for me as i had to manually create the context node and attributes and write code to populate the nodes with values and display in the table.

My original issue was that the table was populated by directly binding the table to the context nodes/attributes which are dictionary references. Because of this i was not able to add my own attribute say my_cell_design (of type WDUI_TABLE_CELL_DESIGN) under the context node. and hence unable to set the celldesign dynamically. So I was hoping if we can somehow identify the table row and set its design programmatically without the need for context attributes. Like if you want to set the column design we can do it (in WDMODIFYVIEW) without needing a context attribute.

wd_table_column ?= view->get_element( <<column name>>).

wd_table_column ->SET_CELL_DESIGN( 01 ).

Anyway since my problem is solved i am marking this thread as answered. I will award points to both of you.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this link. Here I am explaining how to color the table cells conditionally.

http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/user-interface-tech...

Former Member
0 Kudos

Hi

Have a look at sample WD component WDR_TEST_TABLE in package SWDP_TEST.

Here you will find example for all table related functionalities, including table row color.

Manas Dua

Former Member
0 Kudos

The above code i have given is from WDMODIFYVIEW of the view VARIANTS_STANDARD only. But i am getting the error at the highlighted line. ( wd_standard_cell->set_cell_design( cl_wd_abstr_master_table_col=>e_cell_design-badvalue_medium )

Looks like wd_standard_cell needs to be filled with some value before this. Not sure what that is and how to. can you please let me know? in the example program they are filling wd_standard_cell variable with some variant info which is not applicable in my case.

Edited by: Aditya Atluri on Nov 7, 2010 5:20 AM