Skip to Content
avatar image
Former Member

Pass current item to formatter

Hi guys,

I've a table to display the following items:

[
    {
        "ID": "109309714021884",
        "UnitPrice": "4.08",
        "QuantityPicking": "0.0",
        "QuantityShipping": "0.0",
        "QuantityDelivered": "2000.0",
        "QuantityCancelled": "0.0",
        "StatusKey": "Picking"
    },
    {
        "ID": "109309714021906",
        "UnitPrice": "6.53",
        "QuantityPicking": "0.0",
        "QuantityShipping": "0.0",
        "QuantityDelivered": "1000.0",
        "QuantityCancelled": "0.0",
        "StatusKey": "QuantityDelivered"
    }
]

My table is like so:

<Table id="orderTable" items="{SalesOrderItemsNavigation}">
    <columns>
        <Column>
            <Text text="{i18n>detailLineItemTableIDColumn}"/>
        </Column>
        <Column hAlign="End">
            <Text text="{i18n>detailLineItemTableUnitPriceColumn}"/>
        </Column>
        <Column hAlign="End">
            <Text text="{detailView>/tabSpecificQuantityColumn}"/>
        </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <ObjectIdentifier title="{Material}" text="{ID}"/>
                <ObjectNumber number="{parts: ['UnitPrice', 'currency'], type: 'sap.ui.model.type.Currency', formatOptions: { showMeasure: false }}" unit=""
                    emphasized="false" state="None"/>
                <ObjectNumber number="{path: './', formatter: '.formatter.specificQuantity'}"
                    unit="{MeasureUnit}" emphasized="true" state="None"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>

What I want to do is to display based on the StatusKey the corresponding quantity. For example: For the first record the StatusKey is "Picking" so on the first row of my table in the third column (quantity) I want only the "QuantityPicking" value to be displayed.

I know I can achieve this creating one entry of ObjectNumber for each property and then using the visible attribute with an expression, but that is messy.

Is there any good way of achieving this?

I thought about a formatter but the thing is, I don't know how to pass the whole item for the formatter and I don't want to pass the four quantities plus the Status Key as parts.

The formatter method should be something like this:

specificQuantity: function(oObject) {
    var key = "Quantity"+oObject.StatusKey;
    return oObject[key];
}

Any Ideas,

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Nov 13, 2017 at 09:19 AM

    Pass the StatusKey value as below to formatter function

    <ObjectNumber number=

    "{parts: [ { path: 'StatusKey '} ] , formatter : '.formatter.specificQuantity'}"

    Then you can return quantity values based on statusKey value . If you wish to pass more fields to formatter function you can do in similar way

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 13, 2017 at 09:19 AM

    Pass the StatusKey value as below to formatter function

    <ObjectNumber number=

    "{parts: [ { path: 'StatusKey '} ] , formatter : '.formatter.specificQuantity'}"

    Then you can return quantity values based on statusKey value . If you wish to pass more fields to formatter function you can do in similar way

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 10, 2017 at 12:11 AM

    try using factory functions to build your table, in this way you can fill the column based on the row data

    Add comment
    10|10000 characters needed characters exceeded