Chinaunix首页 | 论坛 | 博客
  • 博客访问: 706282
  • 博文数量: 145
  • 博客积分: 3446
  • 博客等级: 中校
  • 技术积分: 1567
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-30 13:58
文章分类

全部博文(145)

文章存档

2021年(1)

2020年(1)

2019年(1)

2018年(6)

2017年(1)

2016年(10)

2015年(12)

2014年(10)

2013年(15)

2012年(33)

2011年(21)

2010年(9)

2009年(18)

2008年(2)

2006年(5)

我的朋友

分类: Web开发

2016-09-20 11:02:06

http://scn.sap.com/community/crm/webclient-ui-framework/blog/2014/05/05/conditional-formatting-for-tables-in-webui

In comments to one of my blog posts I indicated that conditional formatting in tables was quite awaited feature for me. There are plenty of scenarios when we need to highlight or indicate or distinguish something in tables in WebUI. And previous tricks were quite difficult to implement.

Just take a look at these discussions:

How to set particular column or cell color of result view in CRM WEB UI ?

 

I expected that standard implementation would finally take into account already existed P_STYLE and/or P_CLASS changing parameters from IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START method. But it does not. I've already described the issue with table iterator and those parameters in this message Re: How to set particular column or cell color of result view in CRM WEB UI ?

 

And here is the good news. As mentioned in (page 25) "Conditional formatting for Tables" is already available. Partially I think... Now it's much easier to format tables based on some conditions. But "formatting" here means only table cell coloring. I was really surprised because I (again) expected more flexibility in formatting like an option to set styles or CSS classes to cells or rows. Yes, setting background color covers most of the needs. But "coloring" is not "formatting".

 

To be completely sure that there is nothing else in shortly upcoming SPs I raised OSS message and received the oficial answer:

As per development there's no new development considered regarding "Conditional Formatting of the cellerator's cells" at this current time and there is no further information concerning the topic.

 

So how to do conditional formatting? The note introduces this feature. Need to admit that this feature is available starting from SAP CRM 7.0 Ehp1. How-To Guide is attached to the note. With this note we get one more property for table cell. Property name is

if_bsp_wd_model_setter_getter=>fp_bgcolor (or simply 'backgroundColor'). We need to return color name or RGB hexcode as a string (for example 'pink' or '#FFC0CB').

 

So some GET_P method should simply look like:

 

  1. METHOD get_p_.  
  2.   IF iv_property EQ if_bsp_wd_model_setter_getter=>fp_bgcolor  
  3.   AND .  
  4.     rv_value = 'pink'. " or '#FFC0CB'  
  5.   ENDIF.  
  6. ENDMETHOD.  

 

The result is:

Cells.png

 

Cool! But what about a row? Certainly we can go and define as many GET_P methods to return this property as many attributes we have. And implement new GET_P method for each and every new attribute we add in the future.

 

Here I would suggest another way.

  • Define static attribute in your context node class which represents table of pairs 'index; color' for buffering.
  • Redefine GET_P_T_TABLE method of your context node class (inherited from CL_BSP_WD_CONTEXT_NODE_TV class).
  • Handle the backgroundColor property in this method passing all other properties to super-method.
  • For each new index trigger your condition and store the result in the index-color table.
  • Retrieve the color from the table if possible.

 

Here is a code example:

 

  1. METHOD get_p_t_table.  
  2.   DATA: lr_current TYPE REF TO if_bol_bo_property_access.  
  3.   FIELD-SYMBOLS:  TYPE zts_color.  
  4.   IF iv_property = if_bsp_wd_model_setter_getter=>fp_bgcolor.  
  5.     READ TABLE gt_colors ASSIGNING  WITH KEY index = iv_index.  
  6.     IF  IS NOT ASSIGNED.  
  7.       APPEND INITIAL LINE TO gt_colors ASSIGNING .  
  8.       -index = iv_index.  
  9.       lr_current = me->get_bo_by_index(  
  10.           iv_index        = iv_index  
  11.           iv_change_focus = abap_false ).  
  12.       IF lr_current IS BOUND.  
  13. * There are some logic and conditions  
  14. * Here it's based on current line entity in zcl_util_misc=>get_color as an example  
  15.         -color = zcl_util_misc=>get_color( lr_current ).  
  16.       ENDIF.  
  17.     ENDIF.  
  18.     rv_value = -color.  
  19.   ELSE.  
  20.     CALL METHOD super->get_p_t_table  
  21.       EXPORTING  
  22.         component       = component  
  23.         iv_index        = iv_index  
  24.         iv_property     = iv_property  
  25.         iv_display_mode = iv_display_mode  
  26.       RECEIVING  
  27.         rv_value        = rv_value.  
  28.   ENDIF.  
  29. ENDMETHOD.  

 

Where types and attribute are defined as:

  1. PRIVATE SECTION.  
  2.   TYPES:  
  3.     BEGIN OF zts_color,  
  4.           index TYPE i,  
  5.           color TYPE string,  
  6.          END OF zts_color .  
  7.   TYPES:  
  8.     ztt_color TYPE TABLE OF zts_color .  
  9.   DATA gt_colors TYPE ztt_color .  

 

Also we have to clean up gt_colors somewhere after completing the output. Because otherwise there will be issues during next rendering. For example when sorting is applied to this UI table. I used method CLEAR_LAST_LINE in context node class which is also inherited from CL_BSP_WD_CONTEXT_NODE_TV. It's called from handler of CL_BSP_WD_VIEW_CONTROLLER~OUTPUT_RENDERED event and satisfied my needs.

 

And here is the result:

Rows.png

 

Sure enough, it's easier and much better than previous approaches. But still there is a lack of flexibility... Anyway it should cover most of requirements. At least I hope so.

阅读(913) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~