0 votes
1 view
in SAP by (7k points)

I've written an XML view. Inside it there is a table:

<Table xmlns="sap.m"
  id="myTable"
  select=""
  selectionChange=""
  swipe=""
  growingStarted=""
  growingFinished=""
  updateStarted=""
  updateFinished=""
  itemPress="console.log('clicked on item')"
>
  <columns>
    <!-- sap.m.Column -->
  </columns>
  <items>
    <!-- sap.m.ListItemBase -->
  </items>
</Table>

I insert the row to the table using the onInit of the controller, but when I click on a row, the message is not shown.
If I use console.log(tablePippo.getProperty("itemPress")); inside the controller, it throws
 

Uncaught Error: Property "itemPress" does not exist in Element sap.m.Table#operationDetail--myTable

1 Answer

0 votes
by (14.5k points)

As far as my experience allows me to understand, this issue comes up quite frequently when users leverage sap.m.ListBase related controls. 

The confusion is mostly related to the sap.m.ListMode of controls that are inherited from sap.m.ListBase and sap.m.ListType of items that are inherited from sap.m.ListItemBase.

Assuming the following sample List:

<List

  selectionChange=".onSelectionChange"

  itemPress=".onItemPress"

  delete=".onDelete"

>

  <items>

    <ObjectListItem

      title="Hello ListItem"

      press=".onObjectListItemPress"

    />

  </items>

</List>

sap.m.ListMode (Sample)

While using sap.m.List or sap.m.Table, event firing depends on the mode which is being used. Unfortunately, a List or Table without a mode will not fire any event. If the firing of those events is required, users should use

  mode="SingleSelect"

  ...

>

These are the possible modes from the sap.m.ListMode documentation:

None (default)

Since no mode property is assigned, none of the events will be fired!

SingleSelect | SingleSelectLeft

List controls that have a  mode="SingleSelect" show a radio button on the right side of each item and they will fire the onSelectionChange event the moment users click on the given radio button control. Using "SingleSelectLeft" just moves the radio button to the left side of the item.

SingleSelectMaster

List controls with mode="SingleSelectMaster" will show the hand on mouseover and fire the onSelectionChange in case of a click on an item.

MultiSelect

List control in mode="MultiSelect" offer a checkbox and fire the onSelectionChange event on every check and uncheck of an item.

Delete

Using the list in mode="Delete" gives users a delete button and fires the event onDelete.

sap.m.ListType (Sample)

Every item inherits from sap.m.ListItemBase and thus has an attribute called type. 

<items>

  <ObjectListItem

    type="Active"

    press=".onObjectListItemPress"

    detailPress=".onDetailPress"

    ...

  />

</items>

There are these types listed in the sap.m.ListMode documentation:

Active

Depending on the mode, the itemPress of the list and press of the list item can be fired. The selected item gets highlighted so the user can see what's selected.

Detail

A detail button (with icon sap-icon://edit) is offered which fires the detailPress event.

DetailAndActive

As the name says, this is a combination of Detail and Active type. So you have the detail button firing detailPress on button click, and the item itself firing the list event itemPress.

Navigation

The items have a navigation look, and itemPress and item's press are called.

Inactive

No item event gets called from the item itself.

Considering your problem, you should either assign your Table control a mode or assign your items a type. After that, you are required to change the events that should be fired.

Generally, I would avoid using a ListMode and a ListType at the same time since there can be unexpected behavior but check it by yourself.

For more knowledge, you can go through SAP Fiori blog online or also you can join SAP Fiori training  

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...