
DataGrid uses a new approach to processing data. For this reason, a new type of context node is required in which data can be stored. The context node is two-dimenstional. This type is not supported by the ABAP Workbench. For this reason you have to create this context node dynamically and bind it to the relevant property.
You create the context nodes and bind them to the properties in the hook method WDDOMODIFYVIEW.
The following source code is an example of the implementation:
method WDDOMODIFYVIEW .
data l_data_grid type ref to cl_wd_data_grid.
data l_segment type ref to cl_wd_data_grid_segment.
data lt_segments type cl_wd_data_grid_segment=>tt_data_grid_segment.
data l_cell type ref to cl_wd_data_grid_cell.
data l_cells type cl_wd_data_grid_cell=>tt_data_grid_cell.
if first_time = abap_true.
wd_assist->fill_data( ).
l_data_grid ?= view->get_element( 'DATA_GRID' ).
lt_segments = l_data_grid->get_segments( ).
loop at lt_segments into l_segment.
l_segment->bind_data_source( wd_assist->create_node( segment_name = l_segment->get_id( )
root_node = wd_context ) ).
wd_assist->bind_node_data( l_segment ).
" Bind value of cells
l_cells = l_segment->get_templates( ).
loop at l_cells into l_cell.
l_cell->bind_value( l_segment->bound_data_source( ) && '.' && 'VALUE' ).
l_cell->bind_image_source( l_segment->bound_data_source( ) && '.' && 'ICON_SOURCE' ).
endloop.
endloop.
endif.
endmethod.
types:
begin of TS_DATA_GRID ,
wd_tkey_x type i,
wd_tkey_y type i,
value type string,
icon_source type string,
state type WDUI_C_TABLE_HIERACHICAL_STATE,
level type i,
end of ts_data_grid .
types:
tt_data_grid type standard table of ts_data_grid
with non-unique default key
with non-unique sorted key wd_tkey_2d components wd_tkey_x wd_tkey_y . data l_data type ts_data_grid.
data lo_structure_rtti type ref to cl_abap_structdescr.
lo_structure_rtti ?= cl_abap_typedescr=>describe_by_data( p_data = l_data ). data lt_attributes type wdr_context_attr_info_map.
data ls_attributes like line of lt_attributes.
ls_attributes-name = 'VALUE'.
ls_attributes-default_value = lv_segment_id.
insert ls_attributes into table lt_attributes.
ls_attributes-name = 'ICON_SOURCE'.
ls_attributes-default_value = `/sap/public/bc/ur/nw5/themes/sap_corbu/common/libs/Icon/Failure.gif`.
insert ls_attributes into table lt_attributes. data l_node_info type ref to if_wd_context_node_info.
data l_node type ref to if_wd_context_node.
data l_node_2d type ref to if_wd_context_node_2d.
l_node_info = root_node->get_node_info( ).
l_node_info = l_node_info->add_new_child_node(
name = segment_name
is_initialize_lead_selection = abap_false
static_element_rtti = lo_structure_rtti
attributes = lt_attributes
is_2d_node = abap_true
).
l_node = root_node->get_child_node( segment_name ).
l_node_2d ?= l_node. The data with which the context node is filled must meet the following prerequisites: