Cell editors in the DataGrid
You can use aggregation CONTENT to insert cell editors into a DataGridCell.
With properties selectedTemplateKey of DataGridSegment and templateKey of DataGridCell you can specify which cell editor is used to display individual cells within the segment. Use these properties if you want to provide several different cell editors within a segment.
You create the binding of primary attributes of cell editors and property selectedTemplateKey dynamically.
You can use the cell editors:
Example
You would like to use two different cell editors (CInputField und CTextView) in a DataGrid with one segment.
You can find an example in view TC_SIMPLE in component WDR_TEST_DATA_GRID.
- Using aggregation TEMPLATE create two DataGridCells.
- In the first DataGridCell use aggregation CONTENT to insert a CInputField.
- In the second DataGridCell use aggregation CONTENT to insert a CTextView.
- For property templateKey of the first DataGridCell enter a name for the template (e.g. Input).
- For property templateKey of the second DataGridCell enter a name for the template (e.g. text).
- You dynamically bind the primary attributes of the cell editors to the corresponding attribute of the context node (property dataSource of DataGridSegment) and propertyselectedTemplateKey. You can use the following code:
method wddomodifyview . data l_segment type ref to cl_wd_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 . data l_client_input_field type ref to cl_wd_client_input_field . data l_client_text_view type ref to cl_wd_client_text_view . if first_time = abap_true . wd_assist -> initialize ( iv_number_of_seg_rows = 1 iv_number_of_seg_cols = 1 iv_number_of_rows = 5 iv_number_of_columns = 6 ). wd_assist -> fill_data ( ). l_segment ?= view -> get_element ( `DATAGRIDSEGMENT_11` ). 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 ). l_segment -> bind_selected_template_key ( l_segment -> bound_data_source ( ) && `.` && `SELECTED_TEMPLATE_KEY` ). l_client_input_field ?= view -> get_element ( `CLIENT_INPUT_FIELD` ). l_client_input_field -> bind_value ( l_segment -> bound_data_source ( ) && `.` && `VALUE` ). l_client_text_view ?= view -> get_element ( `CLIENT_TEXT_VIEW` ). l_client_text_view -> bind_text ( l_segment -> bound_data_source ( ) && `.` && `VALUE` ). " Bind value of cells " Bind value of cells l_cells = l_segment -> get_templates ( ). loop at l_cells into l_cell . l_cell -> bind_background_color ( l_segment -> bound_data_source ( ) && '.' && 'BACKGROUND' ). endloop . endif . endmethod .