Thursday, June 27, 2013

Summary.

In order to get FILTER or SORTING functions for Table UI element, need to define attribute with ref to IF_WD_TABLE_METHOD_HND interface.

Procedure with steps

  • Create Web Dynpro Component(ZOVH_TABLE_FILTERING_01) with Window and View(Automatically View is embedded into Window).

  • Go to view ->Context tab 
    • Change mode .
    • Create a node IT0001 with cardinality 0-n.


    • Create another node IT0001_FILTER with cardinality 1-1 and selection 1-1. Attributes of node IT0001 and IT0001_FILTER should be same so that we can provide filter for all attributes.

    • Take out Dictionary structure.
    • Take out all attributes of node IT0001_FILTER and replace with STRING type.

    • Create one attribute IS_FILTER_ON with type WDY_BOOLEAN. This attribute is used to switch on or switch off filter option.

  • Go to view->Attributes tab.
    • Create one attribute(TABLE_CONTROL) of type IF_WD_TABLE_METHOD_HNDL interface.  Interface IF_WD_TABLE_METHOD_HNDL provides sorting and filtering functions for a Table UI element.
  • Go to view->Layout tab
    • Set Layout = MatrixLayout of ROOTUIELEMENTCONTAINER.
    • Create table UI element(table_4_filter). 

    • Bind context node IT0001 with table UI element. Follow the below steps.



    • Set filterValue property for each column attribute of table UI element. Similar attribute from node IT0001_FILTER should be mapped to column filterValue property.Follow the steps.

    • Insert Table Toolbar and ToolBarToggleButton element into table UI element for filter.


    • Bind CHECKED property of ToolBarToggleButton element to attribute IS_FILTER_ON defined at context.
    • Change the below highlighted portions as specified. 
    • Create onToggle event(SWITCH_FILTER) for ToolBarToggleButton element.

  • Go to view->Actions tab.
    • Double click on Filter event.
    • Past the below code.
METHOD ONACTIONFILTER .
  WD_THIS->TABLE_CONTROL->APPLY_FILTER( ).
ENDMETHOD.
  • Go to view->Methods tab.
    • Double click on WDDOMODIFYVIEW method and paste the code.
METHOD WDDOMODIFYVIEW .
  CASE FIRST_TIME.
    WHEN ABAP_TRUE.
      "&---------------------------------------------------------------------*
      " Code for data retrieval
      "&---------------------------------------------------------------------*
      DATA LO_ND_IT0001 TYPE REF TO IF_WD_CONTEXT_NODE.
      DATA LT_IT0001 TYPE WD_THIS->ELEMENTS_IT0001.

      " navigate from  to  via lead selection
      LO_ND_IT0001 = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_IT0001 ).

      SELECT * FROM PA0001
         INTO CORRESPONDING FIELDS OF TABLE LT_IT0001 UP TO 20 ROWS.

      LO_ND_IT0001->BIND_TABLE( NEW_ITEMS = LT_IT0001 SET_INITIAL_ELEMENTS = ABAP_TRUE ).
  ENDCASE.

  "&------------------------------------------------------------------------*
  " Code for FILTER
  "&------------------------------------------------------------------------*
  DATA WD_TABLE TYPE REF TO CL_WD_TABLE.
  " Name of the table UI element to be provided
  WD_TABLE ?= VIEW->GET_ELEMENT( 'TABLE_4_FILTER' )."Name of Table UI element
  WD_THIS->TABLE_CONTROL ?= WD_TABLE->_METHOD_HANDLER.


  DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_CONTEXT TYPE WD_THIS->ELEMENT_CONTEXT.
  DATA LV_IS_FILTER_ON TYPE WD_THIS->ELEMENT_CONTEXT-IS_FILTER_ON.

  " get element via lead selection
  LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ).
  " get single attribute
  LO_EL_CONTEXT->GET_ATTRIBUTE(
    EXPORTING
      NAME =  `IS_FILTER_ON` 
    IMPORTING
      VALUE = LV_IS_FILTER_ON ).
  " Set or cancel the table's filter action
  IF LV_IS_FILTER_ON = ABAP_TRUE .
    WD_TABLE->SET_ON_FILTER( 'FILTER' ).
  ELSE.
    WD_TABLE->SET_ON_FILTER( '' ).
  ENDIF.
ENDMETHOD.
  • Save and activate web dynpro component and create web dynpro application.
  • Run web dynpro application. 
  • Click on filter button and filter using any the columns.


1 comment:

  1. Is it possible to check, whether the row of the table is filtered?

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.