Monday 28 September 2015

Cell Variant: A way to use multiple editor in a single table column in webdynpro ALV

Cell Variant is a concept which comes handy when multiple cell editors need to be used for a single table column. 

Let's say we have a table with few columns. Now while using table as UI element, we create binding and while creating binding, we give information for cell editor also that this column of table will be say of type TextView, that column will be of type InputField. So as per the binding table columns will be displayed accordingly. 

That is the static way of creating cell editor for a particular column. Now one can have the requirement of using a different cell editor (than one which we have given during creation of binding) for a particular row based on some condition. At this point cell variant comes into picture. 

The context node which we will be displaying in table will have one extra attribute for cell variant key. This attribute's value will decide which cell editor will be coming into picture for a particular row. So we have to do our calculation in coding and assign appropriate value to this attribute.  

Column, which will be hosting different cell editors, will have the property 'selectedCellVariant' bind to the cell variant key attribute. Cell variant we can insert by right clicking on the column and further by right clicking on the cell variant we can insert the cell editor. In cell variant we have to give value to the property 'variantKey'. In run time for every record, cell variant attribute's value will be matched with this property's value. If it get's matched, corresponding cell editor will be displayed. Please make note that this value is case sensitive, so NOTE and Note will be considered different. 

So We will be doing a simple example on this. Example will have one table with 2 columns. First columns will have some numeric value and based on the first column's value, 2nd column will have different cell editors.

Make one WD component and in main view in context have one node with 2 attribute like below. 2nd attribute will serve the purpose of cell variant key.



In layout insert a table UI element and bind with the context node. In second column set the properties like below.


Under 2nd column insert cell variant like below. Insert one cell editor also per cell variant.








Do coding like below in WDDOINIT method of the view.





Do create one application and test it.


In case for any record the value of cell variant key attribute doesn't match with any existing cell variant's 'variantKey' property, below dump will occur.



Happy Learning :)

No comments:

Post a Comment