cancel
Showing results for 
Search instead for 
Did you mean: 

Setting cell color in ALV

Former Member
0 Kudos

Hi All

I would be greatful if someone could please help...

I am still attempting to get cells painted within a WDA ALV grid display.

I have tried to use the method stated in the WDA sap press book - but this method is for use with TABLE element and I am using a ViewContainerUIElement for my table. There are mentions of wonderful ways to color cells in a list display - but I cannot understand how this can be achieved. I currently have this working appart from the numeric numbers of the design being set into the relavant column cell.

If anyone could help that would be great...



Please see: <a href="http://picasaweb.google.co.uk/dave.alexander69/Pictures#5244800978549492338" TARGET="test_blank">http://picasaweb.google.co.uk/dave.alexander69/Pictures#5244800978549492338</a>

   LOOP AT lt_zdata INTO ls_zdata.

        lv_index = sy-tabix.

*       set column values
*       loop at row data and set colour attributes of individual cells
        LOOP AT lt_columns ASSIGNING <fs_column>.
          lr_col_header = <fs_column>-r_column->get_header( ).
          lr_col_header->set_ddic_binding_field( ).

          CREATE OBJECT lr_input_field EXPORTING value_fieldname = <fs_column>-id.
          lr_column = lr_column_settings->get_column( <fs_column>-id ).

*         for the date columns only...
          IF <fs_column>-id(4) = 'CELL'.

*           get and set column dates from select option user input
            READ TABLE lt_dates INTO ls_dates INDEX 1.
            IF lt_dates IS INITIAL.
              lr_col_header->set_text( 'Date' ).
            ELSE.
              ls_dates-low = ls_dates-low + lv_incr_date.
              MOVE ls_dates-low+2(2) TO lv_for_col_date+6(2).   "Year
              MOVE ls_dates-low+4(2) TO lv_for_col_date+3(2).   "Month
              MOVE ls_dates-low+6(2) TO lv_for_col_date(2).     "Day
              MOVE lv_for_col_date   TO lv_col_date.
              lr_col_header->set_text( lv_col_date ).
              lv_incr_date = lv_incr_date + 7.
            ENDIF.

            LOOP AT lt_orgdata_dates INTO ls_orgdata_dates
              WHERE crew = ls_zdata-crew
                AND position = ls_zdata-position
                AND name = ls_zdata-person
                AND trip_arr >= ls_dates-low
                AND trip_dep <= ls_dates-low.

*             column heading settings
              lr_field = lr_table->if_salv_wd_field_settings~get_field( <fs_column>-id ).
              lr_field->if_salv_wd_sort~set_sort_allowed( abap_false ).

* trying to set cell variants ?@#??!!???
*              lr_cv = lr_column->set_key( ls_zdata-variance ).
*              lr_cv->set_editor( lr_input_field ).
*              lr_cv->set_cell_design( value = '01').
*              lr_column->add_cell_variant( lr_cv ).

* current method of seeting the cell colors... (but puts value in cell!)
              FIELD-SYMBOLS: <fs> TYPE data.
              lr_column->set_cell_design_fieldname( value = <fs_column>-id ).
              ASSIGN COMPONENT <fs_column>-id OF STRUCTURE ls_zdata TO <fs>.
              WRITE: CL_WD_TABLE_COLUMN=>e_cell_design-one TO <fs>.

              MODIFY lt_zdata FROM ls_zdata. " INDEX lv_index.

            ENDLOOP.

          ENDIF.

Kind Regards

Dave Alexander

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank you Priyank & Suman for your responses.

It is still however a problem - as the methods you describe rightly change the color of a column - and with conditional logic can be set to change a specific row. My problem however is that I am setting multiple columns (x) rows with colored cells - and if I set a column at row level it will affect all columns - i.e. switch on coloring for any row column value marked.

This leads me to believe that I would need to use Cell Variants - but cannot figure out how this should work based on my instance.

I live in hope

Many Thanks again

Dave Alexander

Former Member
0 Kudos

Hi Dave,

It is not an issue,how many rows of columns you are assigning colors.

you can assign different colors to the same row of different columns.this is possible with my coding for this you need not use cell variant.

Cell variant is for in a single column if you want to show one cell with drop down another with text in this case you can use cell variant.

check this code some small changes to my previos code.

i have taken anothe attribute celldesign1 to set colors for other column.

loop at it_flights into ls_flights.

move-corresponding ls_flights to ls_final.

if ls_final-price = '185.00'.

ls_final-readonly = abap_true.

ls_final-celldesign =

cl_wd_table_column=>e_cell_design-badvalue_light.

ls_final-celldesign1 =

CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-NEGATIVE.

else.

ls_final-readonly = ' '.

ls_final-celldesign =

cl_wd_table_column=>e_cell_design-goodvalue_light.

ls_final-celldesign1 =

CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-POSITIVE.

endif.

append ls_final to it_final.

endloop.

*Give colors to cells

l_column1 = l_value->if_salv_wd_column_settings~get_column( 'CARRID' ).

l_column1->set_cell_design_fieldname( value = 'CELLDESIGN' ).

l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN' )

.

l_column2 = l_value->if_salv_wd_column_settings~get_column( 'CONNID' ).

l_column2->set_cell_design_fieldname( value = 'CELLDESIGN1' ).

l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN1' )

.

is this the solution you are looking.Please back to me if you have any issues.

Thanks

Suman

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Suman

I have implemented that as you suggested successfully - all is good now in the world of WDA!

Thank you very much for your help.

P.S. you don't know how to dynamically add table colum groups to and WDA ALV do you?

Cheers

~Dave Alexander

Former Member
0 Kudos

Hi Suman

Great - I see what you mean - I must therefore assign a celldesign attribute for each one of my columns I intend to modify. I can see this working - I will give it a try and get back to you with results.

Thank you again for you time and efforts,

Dave

Former Member
0 Kudos

Hi check this code to set cell colors for ALV grid.

Take a context attribute with type WDUI_TABLE_CELL_DESIGN.

Here i am populating colors based on some condition.Check the loop of the internal table.

method get_flight_details .

data:node_flights type ref to if_wd_context_node,
     it_flights type sflight_tab1,
     ls_flights type sflight,
     it_final type   if_componentcontroller=>elements_flights,
     ls_final type   if_componentcontroller=>element_flights.

    select * from sflight into table it_flights
 up to 100 rows.
    node_flights = wd_context->get_child_node( 'FLIGHTS' ).

    loop at it_flights into ls_flights.
       move-corresponding ls_flights to ls_final.
       if ls_final-price = '185.00'.
          ls_final-readonly = abap_true.
          ls_final-celldesign =
cl_wd_table_column=>e_cell_design-badvalue_light.
       else.
          ls_final-readonly = ' '.
          ls_final-celldesign =
cl_wd_table_column=>e_cell_design-goodvalue_light.
       endif.
       append ls_final to it_final.
    endloop.

    node_flights->bind_table(
        new_items            = it_final
        set_initial_elements = abap_true
*        INDEX                = INDEX
           ).



 data: l_ref_cmp_usage type ref to if_wd_component_usage.

 l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
 if l_ref_cmp_usage->has_active_component( ) is initial.
   l_ref_cmp_usage->create_component( ).
 endif.

 data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
 l_ref_interfacecontroller =   wd_this->wd_cpifc_alv( ).
   data:
     l_value type ref to cl_salv_wd_config_table.

   l_value = l_ref_interfacecontroller->get_model(
   ).

* Make Price column editable
 data:l_column type ref to cl_salv_wd_column,
      l_column1 type ref to cl_salv_wd_column,
      lr_input type ref to cl_salv_wd_uie_input_field,
      l_input1 type ref to cl_salv_wd_uie_input_field.

l_column = l_value->if_salv_wd_column_settings~get_column( 'PRICE' ).

create object lr_input
  exporting
    value_fieldname = 'PRICE'
    .
l_column->set_cell_editor( value = lr_input ).
* to make some cells non editable
lr_input->set_read_only_fieldname( value = 'READONLY' ).

 l_value->if_salv_wd_column_settings~delete_column( id = 'READONLY'   )
.
*Set the table Editable
l_value->if_salv_wd_table_settings~set_read_only( value = abap_false ).

*Give colors to cells
l_column1 = l_value->if_salv_wd_column_settings~get_column( 'CARRID' ).
l_column1->set_cell_design_fieldname( value = 'CELLDESIGN'  ).

 l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN' )
.
endmethod.

Thanks

Suman

Former Member
0 Kudos

see if you find this useful..