Skip to Content
0

Pass current item to formatter

Nov 08, 2017 at 05:41 PM

33

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
tisha dharod Nov 13, 2017 at 09:19 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
tisha dharod Nov 13, 2017 at 09:19 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Srikanth KV Nov 10, 2017 at 12:11 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded