Search code examples
sapui5

SAPUI5 SmartTable itemPressed - get pressed cell


is there any chance to get the value of the pressed cell in the itemPress event ? I would like to set a tooltip when somebody presses a cell in a column. Alternatively, is it possible to register this event on a cell only ?

I am using SmartTable (responsive -> sap.m.table) based on XML View:

                <smartTable:SmartTable
                                id="kubas"
                                entitySet="myEntity"
                                initiallyVisibleFields="absender,empfaenger,nachtyp"
                                smartFilterId="smartFilterBar" 
                                tableType="ResponsiveTable" 
                                useExportToExcel="true" 
                                useVariantManagement="true" 
                                useTablePersonalisation="true" 
                                header="Entries" 
                                showRowCount="true" 
                                persistencyKey="SmartTableAnalytical_Explored" 
                                enableAutoBinding="true" 
                                demandPopin="true" 
                                class="sapUiResponsiveContentPadding"
                                dataReceived="onDataReceived"
                                >

            </smartTable:SmartTable>

Or would it be better to somehow incorporate an icon / image to the cells value and set the tooltip for it ?


Solution

  • It is generally not a very good practice to set tooptip by itemPress event of a cell.

    Either you can set a tooltip in Column header or you can customize your Column item showing tooltip.

    You can customize your inner table of SmartTable, for example, Column header and Column item like below. More info please see here.

    <smartTable:SmartTable entitySet="LineItemsSet"
        smartFilterId="smartFilterBar" tableType="ResponsiveTable"
        useExportToExcel="true" useVariantManagement="false"
        useTablePersonalisation="true" header="Line Items" showRowCount="true"
        persistencyKey="SmartTableAnalytical_Explored" enableAutoBinding="true"
        demandPopin="true" class="sapUiResponsiveContentPadding">
        <Table>
            <columns>
                <Column width="100px" hAlign="Left">
                    <customData>
                        <core:CustomData key="p13nData"
                            value='\{"columnKey": "Dmbtr", "maxLength": "5","columnIndex":"4", "leadingProperty": "Dmbtr"}' />
                    </customData>
                    <Text text="{/#LineItems/Dmbtr/@sap:label}" />
                </Column>
            </columns>
            <items>
                <ColumnListItem>
                    <cells>
                        <Text
                            text="{Dmbtr}" />
                    </cells>
                </ColumnListItem>
            </items>
        </Table>
    </smartTable:SmartTable>
    

    Set tooltip for column header if you want to show general information regarding this column.

    <columns>
        <Column width="100px" hAlign="Left">
            <customData>
                <core:CustomData key="p13nData"
                    value='\{"columnKey": "Dmbtr", "maxLength": "5","columnIndex":"4", "leadingProperty": "Dmbtr"}' />
            </customData>
            <Text text="{/#LineItems/Dmbtr/@sap:label}" tooltip = "YOUR TOOLTIP"/>
        </Column>
    </columns>
    

    Set tooltip for each individual cell.

    <items>
        <ColumnListItem>
            <cells>
                <Text text="{Dmbtr}" tooltip = "YOUR TOOLTIP"/>
            </cells>
        </ColumnListItem>
    </items>