cancel
Showing results for 
Search instead for 
Did you mean: 

Grouping repetitive items in XML table

Former Member
0 Kudos

Hi Experts,

I have a xml table displaying certain fields from my odata. The data in the fields have duplicates (PFA). I want to group those duplicates displaying them only once and also pass the count of their occurence as a table field.

Please provide your suggestions as to how this can be accomplished, I have been sitting with this for quite sometime.

Note: In the attachment I have a repetitive occurrence of Power Wheel Chair which comes from the odata. I want to group them together and display only once. Further I also want the count of their occurence.

Regards,

Srinivasan

Accepted Solutions (0)

Answers (1)

Answers (1)

Caspar_van_t
Explorer
0 Kudos

Hi Srinivasan,

What kind of table are you using?
sap.m.Table has the possibility to merge duplicate records, if they are indeed duplicates (in your model).

If this does not work for you, I think that you have to go through the data in code yourself.

But, the recommended way is using the mergeDuplicates property:

http://help.sap.com/saphelp_hanaplatform/helpdata/en/4c/98cf1b07754d22bed8b6fba68f2031/content.htm

Greets,

Caspar

Former Member
0 Kudos

Hi Caspar,

Thank you for you suggestion. This is the table in my xml view

<Table id="ibaseTable" inset="false"

                                        items="{path:'/ServiceRequestCollection', sorter : { path: 'ProductID', group: true }, filters: { path: 'CustomerID', operator: 'EQ', value1: '1001192' } }">

                                        <headerToolbar>

                                            <Toolbar width="100%" height="30%" id="assetbasetbl">

                                                <content>

                                                    <ToolbarSpacer id="tb1"/>

                                                </content>

                                            </Toolbar>

                                        </headerToolbar>

                                        <columns>

                                            <Column>

                                                <Text text="Product"/>

                                            </Column>

                                            <Column>

                                                <Text text="Total"/>

                                            </Column>

                                            <Column>

                                                <Text text="Status"/>

                                            </Column>

                                        </columns>

                                        <items>

                                            <ColumnListItem type="Navigation" press="toDetail1">

                                                <cells>

                                                    <ObjectIdentifier title="{ProductID}"/>

                                                    <ObjectIdentifier title="{ProductID.count}"/>

                                                    <ObjectIdentifier title="Active"/>

                                                </cells>

                                            </ColumnListItem>

                                        </items>

                                    </Table>

Guess this is sap.m.Table. If so please suggest the mergin part in the controller.

Regards,
Srinivasan

Caspar_van_t
Explorer
0 Kudos

Hi Srinivasan,

Please read the document I stated before.

In your column definition the mergeDuplicates property should be added.

Please try the following product column definition (I'm assuming you want to merge these):

<Column mergeDuplicates="true">

    <Text text="Product"/>

</Column>

Greets,

Caspar

Former Member
0 Kudos

Thank you Caspar, this was my exact requirement. So blind of me to never explore that option. Is it possible to display the count of the duplicates in a separate field.

Caspar_van_t
Explorer
0 Kudos

Hi Srinivasan,

As far as I know, SAPUI5 does not have a standardised way to do this.

Some options for you:

- Loop through the data and put your findings in a model, then bind it

- Use a formatter to count all values of one kind

- Create a custom control and use the mergeFunctionName property to call your own grouping function (See JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.m.Column for some more detail on this)

I hope you can find a way to do so correctly, if you got a solution please let us know

Thanks,

Caspar

Former Member
0 Kudos

Hello Caspar,

I tried the second way of using formatter. Below is the code in the formatter. Hope I have done the loop properly

countProducts: function(e) {

            var m = sap.ui.getCore().getModel();

            var items = this.byId("ibaseTable").getItems();

            for (var item_index = 0; item_index < items.length; item_index++) {

                var item = items[item_index];

                (function(_item) {

                    $.get(

                        m.sServiceUrl +

                        _item.getBindingContextPath() +

                        "/ServiceRequestCollection/ProductID/$count",

                        function(count) {

                            _item.setNumber(count);

                        });

                });

            }

        },

I am not sure how to bind this with my table column.

Regards,

Srinivasan