cancel
Showing results for 
Search instead for 
Did you mean: 

Table Binding SAP.M.TABle

nagarjun_kalletla
Participant
0 Kudos

Hi ,

Am very new to SAP UI 5 , started devlopeing a Table in SAP.M.Table

Here is my XML View and copied and modified from Explored demo



<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"

xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:model="sap.ui.model"

controllerName="tableviewsettings.TableView" xmlns:html="http://www.w3.org/1999/xhtml">

<l:VerticalLayout width="100%">

<l:content>

<Table id="idEmployeeTable" items="{Emp>/EmployeeCollection}">

<headerToolbar>

<Toolbar>

<Title text="Employee Details" level="H2" />

<ToolbarSpacer></ToolbarSpacer>

<Button icon="sap-icon://drop-down-list" press="handleViewSettingsDialogButtonPressed" />

</Toolbar>

</headerToolbar>

<infoToolbar>

<Toolbar id="vsdFilterBar" active="true" visible="false"

press="[handleViewSettingsDialogFilterBarPressed, views.control.tableViewSettingsDialog]">

<Label id="vsdFilterLabel" text="?" />

</Toolbar>

</infoToolbar>

<columns>

<Column width="12em">

<Text text="Employee Id" />

</Column>

<Column minScreenWidth="Tablet" demandPopin="true">

<Text text="Employee Name" />

</Column>

<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">

<Text text="Title" />

</Column>

<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">

<Text text="Hire Date" />

</Column>

<Column hAlign="Center">

<Text text="City" />

</Column>

<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">

<Text text="Region" />

</Column>

<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">

<Text text="Postal code" />

</Column>

<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">

<Text text="Country" />

</Column>

</columns>

<items>

<ColumnListItem>

<cells>

<ObjectIdentifier title="{Emp>/EmpID}"  /> <!-- text="{ProductId}" -->

<Text text="{Emp>Name}" />

<Text text="{Emp>Title}" />

<Text text="{Emp>Jdate}" />

<Text text="{Emp>City}" />

<Text text="{Emp>Region}" />

<Text text="{Emp>Pcode}" />

<Text text="{Emp>Country}" />

</cells>

</ColumnListItem>

</items>

</Table>

</l:content>

</l:VerticalLayout>

</mvc:View>


In Controller onInit I have written below code



onInit : function() {

var ctrlr = this;

var dataEmp = {

 

EmployeeCollection :

[ {

"EmpID" : "31017024",

"Name" : "Nagarjun Kalletla",

"Title" : "Phani",

"Jdate" : "14-07-2014",

"City" : "Bangalore",

"Region" : "Kar",

"Pcode" : "560100",

"Country" : "India" }]


},

var oModel = new sap.ui.model.json.JSONModel("mock.json");    " This code I found some where in SCN not working

 

  this.getView().setModel(oModel, "Emp");




Am getting below error ...


When I tried using this below code



var ctrlr = this;

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

oModel.setData(dataEmp);

 

var oTable = ctrlr.getView().byId("idEmployeeTable");

oTable.setModel(oModel);

 

oTable.bindAggregation("items","/EmployeeCollection");

Am getting

Missing template or factory function for aggregation items of Element sap.m.Table#idTableView1--idEmployeeTable !



Can any body help me to solve this issue...


Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

so technically you dont have to do binding in js as you already have it

...items="{Emp>/EmployeeCollection}"...

...

<items>

   <ColumnListItem>

   <cells>

jsut try

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

var oTable = ctrlr.byId("idEmployeeTable");

oTable.setModel(oModel, "Emp");

and that should be enough

nagarjun_kalletla
Participant
0 Kudos

this worked .....

I have changed my controller code ....

var ctrlr = this;

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

        oModel.setData(dataEmp);

        var oTable = ctrlr.getView().byId("idEmployeeTable");

        oTable.setModel(oModel,"Emp");

That's it it worked .....

former_member182372
Active Contributor
0 Kudos

two things are redundant - calling setData on a model as it takes it as constructor parameter and calling getView() to call byId as controller byId does the same thing, keep your code clean

Former Member
0 Kudos

Yes

Its worked

Answers (4)

Answers (4)

ahmed_ayad
Explorer
0 Kudos

after set model for the table try this code

var zBinding = zTable.bindItems({path: "/itemstit", template:zTable.getBindingInfo("items").template});

Former Member
0 Kudos

oTable.setModel(oModel,"Emp");

oTable.bindAggregation("items","Emp>/EmployeeCollection");

santhu_gowdaz
Active Contributor
0 Kudos

in view,

<ColumnListItem id="itemid">


in controller,

oTable.bindAggregation("items", "{Emp>/EmployeeCollection}", ctrlr.getView().byId("itemid"));

Former Member
0 Kudos

Hi Nagarjun,

please look at the example  in  SAPUI5 Explored

Regards

Pandu