Monday, 2 November 2015

why sap.ui.getCore().setModel() is used in sapui5?

this is used mainly for the storing the data in page and access the data in another page.like global access.


var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(mData);
this.getView().setModel(oModel);
//set the objects here
sap.ui.getCore().setModel(oModel, "FirstData");
 sap.ui.getCore().setModel(oModel, "SecondData");



//acces in any control...like following


var globalModel_one = sap.ui.getCore().getModel("FirstData");
this.getView().byId("table").setModel(globalModel_one);

here table  is the id of the Table..

the structure should like


<Table id="table" items="{/ProductCollection}" mode="Delete" delete="odelete">
<columns>
<Column>
<Text text="First Name" />
</Column>
<Column>
<Text text="Last Name" />
</Column>

</columns>
<items>
<ColumnListItem id="list">
<cells>
<Link id="link" text="{UoM}" press="handlePress" />

</cells>
<cells>

<Text text="{UoM}" />
</cells>


</ColumnListItem>
</items>

</Table>


Sunday, 1 November 2015

how to add the json data from the simple local .json file in sapui5 ?

step 1: create a folder on web content ..such that webcontent/yourjsonfile/kkk.json

Step2:


in your controller oninit()

just add the 


var oBusy = new sap.m.BusyDialog();
var oModel = new sap.ui.model.json.JSONModel();
oModel.attachRequestSent(function() {
oBusy.open();
});


oModel.loadData("myfoldername/kkk.json");
oModel.attachRequestCompleted(function() {
oBusy.close();
});
// oModel.setData(mData);
this.getView().setModel(oModel);


step 3:



<Table id="table" items="{/ProductCollection}" mode="Delete" delete="odelete">
<columns>
<Column>
<Text class="firstname_class" text="First Name" />
</Column>
<Column>
<Text class="lastname_class" text="Last Name" />
</Column>
</columns>
<items>
<ColumnListItem id="list">
<cells class="cellclassdata">
<Link id="link" text="{Category}" press="handlePress" />

</cells>
<cells>

<Text class="shipcity_class" text="{Category}" />
</cells>
</ColumnListItem>
</items>

</Table>


step4:

sample kkk.json 

{
"ProductCollection": [
{
"ProductId": "1239102",
"Name": "Power Projector 4713",
"Category": "Projector",
"SupplierName": "Titanium",
"Description": "A very powerful projector with special features for Internet usability, USB",
"WeightMeasure": 1467,
"WeightUnit": "g",
"Price": 856.49,
"CurrencyCode": "EUR",
"Status": "Available",
"Quantity": 3,
"UoM": "PC",
"Width": 51,
"Depth": 42,
"Height": 18,
"DimUnit": "cm",
"ProductPicUrl": "https://openui5.hana.ondemand.com/test-resources/sap/ui/demokit/explored/img/HT-6100.jpg"
},
{
"ProductId": "2212-121-828",
"Name": "Gladiator MX",
"Category": "Graphics Card",
"SupplierName": "Technocom",
"Description": "Gladiator MX: DDR2 RoHS 128MB Supporting 512MB Clock rate: 350 MHz Memory Clock: 533 MHz, Bus Type: PCI-Express, Memory Type: DDR2 Memory Bus: 32-bit Highlighted Features: DVI Out, TV Out , HDTV",
"WeightMeasure": 321,
"WeightUnit": "g",
"Price": 81.7,
"CurrencyCode": "EUR",
"Status": "Discontinued",
"Quantity": 10,
"UoM": "PC",
"Width": 34,
"Depth": 14,
"Height": 2,
"DimUnit": "cm",
"ProductPicUrl": "https://openui5.hana.ondemand.com/test-resources/sap/ui/demokit/explored/img/HT-1071.jpg"
}
]
}




how to append the simple json data to the table in sapui5 ?

your xml should conatin the table element


<Table id="table" items="{/items}" mode="Delete" delete="odelete">
<columns>
<Column>
<Text text="First Name" />
</Column>
<Column>
<Text text="Last Name" />
</Column>
</columns>
<items>
<ColumnListItem id="list">
<cells>
<Link id="link" text="{text1}" press="handlePress" />
</cells>
<cells>

<Text text="{text2}" />
</cells>
</ColumnListItem>
</items>

</Table>




and your controller should load the model data in oninit()




var data = {
"items" : [ {
"text1" : "Rajendra",
"text2" : "Asuri",
"text3" : "M",
"text4" : "001"
}, {
"text1" : "Lakshmana Rao",
"text2" : "Gondi",
"text3" : "M",
"text4" : "002"
}, {
"text1" : "Lakshmi",
"text2" : "Gondi",
"text3" : "F",
"text4" : "003"
} ]

};
var oModel = new sap.ui.model.json.JSONModel(data);
this.getView().byId("table").setModel(oModel);


how to add data to the json data to the combo box in sapui5 ?


use this method in the init method of your  controller.


var mData = {
"combotype":"ComboText",
"rajendra" : [{
"Name" :"Jan",
"Value":"1"
},
{
"Name" :"Feb",
"Value":"2"
},
{
"Name" :"March",
"Value":"3"
}]
};

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(mData);
this.getView().setModel(oModel);




and your xml view should contain 


<ComboBox   class ="Combo_box1" items="{/rajendra}" >
<items>
<core:Item key="{Name}" text="{Value}" />
</items>
</ComboBox>

How to read the json data in sapui5 ?


use this method in the init method of your  controller.


var mData = {

"combotype":"ComboText",
"rajendra" : [{
"Name" :"Jan",
"Value":"1"
},
{
"Name" :"Feb",
"Value":"2"
},
{
"Name" :"March",
"Value":"3"
}]

};

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(mData);
this.getView().setModel(oModel);




and your xml view should contain


<ComboBox   class ="Combo_box1" items="{/rajendra}" >
<items>
<core:Item key="{Name}" text="{Value}" />
</items>
</ComboBox>