cancel
Showing results for 
Search instead for 
Did you mean: 

Data Modeling for controls using XML views(SAPUI5)

mahesh_z
Participant
0 Kudos

Hello ,

I am trying to create Table control using XML view and binding data to it through controller onInit method.

XML View Code is as follows :

<core:View xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core">

    <l:VerticalLayout width="100%">

        <l:content>

            <Text id="description" class="marginAll" />

            <Table id="idProductsTable" items="{       

                path:'/businessData'

            }">

                <headerToolbar>

                    <Toolbar>

                        <Label text="Products"></Label>

                    </Toolbar>

                </headerToolbar>

                <columns>

                    <Column>

                        <Label text="Product" />

                    </Column>

                    <Column>

                        <Label text="Supplier" />

                    </Column>

                    <Column>

                        <Label text="Dimensions" />

                    </Column>

                </columns>

                <items>

                    <ColumnListItem>

                        <cells>

                            <ObjectIdentifier title="{COUNTRY}" text="{COUNTRY}" />

                        </cells>

                        <Text text="{REGION}"></Text>

                        <Text text="{CITY}"></Text>

                    </ColumnListItem>

                </items>

            </Table>

        </l:content>

    </l:VerticalLayout>

</core:View>

Controller onInit method Code is as follows :

var oData = {

            businessData : [ {

                'COUNTRY' : "Canada",

                'CITY' : "Toronto",

                'REGION' : "US",

                'LANGUAGE' : "English"

            }, {

                'COUNTRY' : "China",

                'CITY' : "Bejeing",

                'REGION' : "Ashia",

                'LANGUAGE' : "Chinese"

            } ]

        };

       

        var demoJSONModel = new sap.ui.model.json.JSONModel();

        demoJSONModel.setData(oData);

        sap.ui.getCore().getElementById("idProductsTable").setModel(

                demoJSONModel);

Same thing when i tried with JS views , it worked however through XML view , I am getting empty table.

Is the data modeling correct for XML views?

Thanks,

Mahesh.

Accepted Solutions (1)

Accepted Solutions (1)

ChandraMahajan
Active Contributor
0 Kudos
mahesh_z
Participant
0 Kudos

Hi Chandra,

Thanks a lot for your help. Its working fine for me now after adding the line inside index.html.

As suggested by Sakthivel , I added controllerName and one more change i have done in controller .

//   sap.ui.getCore().byId("idProductsTable").setModel(demoJSONModel);
   this.getView().byId("idProductsTable").setModel(demoJSONModel);

Thanks ,

Mahesh.

Former Member
0 Kudos

Hi Mahesh,

I don't think its required for you to add data-sap-ui-xx-bindingSyntax="complex" ! I guess the only issue was not adding the controllerName. Can you try without bindingSyntax?

Regards

Sakthivel

mahesh_z
Participant
0 Kudos

Hi Sakthivel ,

I tried without data-sap-ui-xx-bindingSyntax="complex" and again the table is empty, Added that line again and data started coming. I guess this line is needed.


Thanks ,

Mahesh.

Former Member
0 Kudos

Okay!! But i don't see you doing any complex binding there! Are you formatting the bind data in your controller ?

Former Member
0 Kudos

I've got it ! The reason for that is you bind items as below,

     <Table id="idProductsTable" items="{    

                path:'/businessData'

            }">

This pattern is followed if you wanna add a formatter/sorter/grouping.

As you don't do any of those you can bind items as below &  it doesn't require  data-sap-ui-xx-bindingSyntax="complex".


<Table id="idProductsTable" items="{/businessData}">

mahesh_z
Participant
0 Kudos

Hey,

I tried this , and this worked as well without any change in index.html

Thanks a lot for your help.

Thanks,

Mahesh

Answers (1)

Answers (1)

Former Member
0 Kudos

You've missed the controllerName property in the xml!

<core:View xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:core="sap.ui.core" controllerName="your-controller-name">


Regards

Sakthivel