Custom Transition for sap.m.App - sapui5

I want to write a custom transition for sap.m.Page transitions.
How Do I start off with this?
Exactly I want to know regarding any documentation, How to create a custom transition and register the same so that it can be used in an SAP UI5 Application.
Thanks in Advance

A Sample implementation of custom transition when App navigates. Click on the list item to find the transition. There is no documentaion on it. This is just a hack.
jQuery.sap.require('sap.m.NavContainer');
jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-core');
jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-effect')
jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-effects-core');
jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-effects-clip');
sap.m.NavContainer.transitions["custom"] = {
to: function(oFromPage, oToPage, fCallback) {
window.setTimeout(function(){
oFromPage.$().toggle("clip");
oToPage.$().toggle("clip");
fCallback();
},600);
},
back: function(oFromPage, oToPage, fCallback) {
window.setTimeout(function(){
debugger;
oFromPage.$().toggle("clip");
oToPage.$().toggle("clip");
fCallback();
},600);
}
};/* code for transition */
var data = {
names: [
{firstName: "Peter", lastName: "Mueller"},
{firstName: "Petra", lastName: "Maier"},
{firstName: "Thomas", lastName: "Smith"},
{firstName: "John", lastName: "Williams"},
{firstName: "Maria", lastName: "Jones"}
]
};
// create a Model with this data
var model = new sap.ui.model.json.JSONModel();
model.setData(data);
var list = new sap.m.List({
headerText:"Names"
});
list.bindItems({
path : "/names",
sorter : new sap.ui.model.Sorter("lastName"),
template : new sap.m.StandardListItem({
title: "{lastName}",
description: "{firstName}",
type: sap.m.ListType.Navigation,
press:function(evt){
var oBindingContext = evt.getSource().getBindingContext();
page2.setBindingContext(oBindingContext);
app.to("page2","custom");
}
})
});
// create the page holding the List
var page1 = new sap.m.Page("page1",{
title: "List Page",
content : list
});
// create the detail page
var page2 = new sap.m.Page("page2", {
title: "Detail Page",
showNavButton: true,
navButtonPress: function(){
app.back();
},
content : [
new sap.ui.layout.form.SimpleForm({
title: "Details for {firstName} {lastName}",
content: [
new sap.m.Label({text: "First Name"}),
new sap.m.Text({text: "{firstName}"}),
new sap.m.Label({text: "Last Name"}),
new sap.m.Text({text: "{lastName}"})
]
})
]
});
// create a mobile App holding the pages and place the App into the HTML document
var app = new sap.m.App({
pages: [page1, page2]
}).placeAt("content");
// set the model to the App; it will be propagated to the children
app.setModel(model);
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<title>Custom jQuery transition</title>
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m,sap.ui.layout"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-theme="sap_bluecrystal"></script>
</head>
<body id="content" class="sapUiBody">
</body>
</html>

Related

SelectedItem BindingContext not found UI5 application

I am trying to find the binding context of the selectedItem. Even after passing modelName to bindingContext, I get undefined. When I do oEvent.getSourcer() and see the oBindingContexts it is blank. Also the oBindingInfos has ocontext undefined. Though it has sPath. The correct sPath. How can I get the array index in this scenario?
oNewField = new sap.m.Select({
enabled: "{order>/" + Type+ "/" + i + "/fieldEnabled}",
forceSelection: false,
width: "90%",
// Add dropdoen Items
items: [
new sap.ui.core.ListItem({
key: " ",
text: " "
}),
new sap.ui.core.ListItem({
key: "{order>/" + Type+ "/" + i + "/DefaultValue}",
text: "{order>/" + Type+ "/" + i + "/DefaultValue}"
})
],
change : function(evt) {
that.onChange(evt);
},
});
var selectedKey = this.getView().getModel('order').getProperty(
"/" + Type+ "/" + i + "/DefaultValue");
oNewField.setSelectedKey(selectedKey);
**On Change Function **
onChange: function(oEvent) {
debugger;
var key = oEvent.getSource().getSelectedItem().getKey();
//need to get BindingContext here.
var oContext =
oEvent.getSource().getSelectedItem().getBindingContext('order')
//gives undefined
},
You are not doing any aggregation binding at all. Therefore there is no context to retrieve. You are hardcoding 2 items in your items aggregation.
Check this snippet. It shows you multinple things you can do. I hope onw of them is what your are looking for.
JSBIN: https://jsbin.com/kumudufaje/edit?html,output
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta charset="utf-8">
<title>MVC with XmlView</title>
<!-- Load UI5, select "blue crystal" theme and the "sap.m" control library -->
<script id='sap-ui-bootstrap'
src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
data-sap-ui-theme='sap_belize_plus'
data-sap-ui-libs='sap.m'
data-sap-ui-xx-bindingSyntax='complex'></script>
<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
<!-- define a new (simple) View type as an XmlView
- using data binding for the Button text
- binding a controller method to the Button's "press" event
- also mixing in some plain HTML
note: typically this would be a standalone file -->
<script id="view1" type="sapui5/xmlview">
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller">
<Panel id="myPanel">
</Panel>
</mvc:View>
</script>
<script>
// define a new (simple) Controller type
sap.ui.controller("my.own.controller", {
onInit: function(oEvent){
//aggregation binding
var oSelect = new sap.m.Select({
items: {
path: 'order>/options',
template: new sap.ui.core.Item({
key: {
path: 'order>key'
},
text: {
path: 'order>value'
}
})
},
change: this.onSelection1Change.bind(this)
});
this.getView().byId("myPanel").addContent(oSelect);
for(var i=0; i<3; i++){
//hardcoded items
var oSelect2 = new sap.m.Select({
items: [
new sap.ui.core.ListItem({
key: '',
text: ''
}),
new sap.ui.core.ListItem({
key: {path:'order>/Type/' + i + '/DefaultValue'},
text: {path:'order>/Type/' + i + '/DefaultValue'}
}),
],
change: this.onSelection2Change.bind(this)
});
this.getView().byId("myPanel").addContent(oSelect2);
}
},
onSelection1Change(oEvent){
var oContext = oEvent.getSource().getSelectedItem().getBindingContext('order')
console.log(oContext); //This prints the binded context
var oModel = oContext.getModel();
console.log(oModel); //This prints the whole model
var oSelectedEntry = oModel.getProperty(oContext.getPath());
console.log(oSelectedEntry); //This prints the data
},
onSelection2Change(oEvent){
var sKey = oEvent.getSource().getSelectedItem().getKey();
console.log(sKey); //This prints the selected item key
var sValue = oEvent.getSource().getSelectedItem().getKey();
console.log(sValue); //This prints the selected item value
var oKeyBinding = oEvent.getSource().getSelectedItem().getBinding('key')
console.log(oKeyBinding); //This prints the binding of the key property, if any
if(oKeyBinding){
var oModel = oKeyBinding.getModel();
console.log(oModel); // This prints the model binded key property, if any
}
}
});
/*** THIS IS THE "APPLICATION" CODE ***/
// create some dummy JSON data
var data = {
options: [{
key: '1',
value: 'option 1'
},{
key: '2',
value: 'option 2'
},{
key: '3',
value: 'option 3'
}],
Type:[
{DefaultValue: 'Default Value1'},
{DefaultValue: 'Default Value2'},
{DefaultValue: 'Default Value3'}
]
};
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData(data);
// instantiate the View
var myView = sap.ui.xmlview({viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above
myView.setModel(oJSONModel, "order");
// put the View onto the screen
myView.placeAt('content');
</script>
</head>
<body id='content' class='sapUiBody'>
</body>
</html>
oEvent.getSource().getSelectedItem().getBindingContext()
You've got it completely right. Note that oEvent.getSource() points to the sap.m.Select. You need another getSelectedItem() to go to the selected sap.ui.core.Item.

How to add "select" in dojo tooltipdialog content programmatically?

I want to display dojo select inside a dijit/TooltipDialog. The items of the dojo select are dynamically loaded. So I want to add this select programmaticaly. The content of TooltipDialog can be an object but select needs a domNode to be held. The code is :
<head>
<script>
require([
"dojo/parser",
"dijit/form/Select",
"dijit/TooltipDialog",
"dojo/on",
"dojo/dom",
"dojo/_base/lang",
"dijit/popup",
"dojo/data/ObjectStore",
"dojo/store/Memory",
"dojo/domReady!"
], function(parser,Select,TooltipDialog,on,dom,lang,popup, ObjectStore, Memory){
parser.parse();
var t={mySel:null};
var store = new Memory({
data: [
{ id: "foo", label: "Foo" },
{ id: "bar", label: "Bar" }
]
});
var os = new ObjectStore({ objectStore: store });
t.mySel = new Select({
store: os
}, "ttt");
var myTooltipDialog = new TooltipDialog({
content: t,
onMouseLeave: function(){
popup.close(myTooltipDialog);
}
});
on(dom.byId("mmm"),"mouseover" ,lang.hitch(this,function(e){
popup.open({
popup: myTooltipDialog,
orient: ["above-centered","above","below"],
around:dom.byId('mmm')
});
t.mySel.startup();
}));
t.mySel.on("change", function(){
console.log("my value: ", this.get("value"))
})
})
</script>
</head>
<body class="claro">
<div id="ttt" > tttt</div><br>
<div id="mmm" > tttt</div><br>
</body>
You are assignign an object t the tooltip content not a domenode
so try to make these change :
var myTooltipDialog = new TooltipDialog({
content: t.mySel.domNode,
onMouseLeave: function() {
popup.close(myTooltipDialog);
}
}

Not able to bind column data when there is space in json

<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>OData Date Table Multiple Sorters</title>
<link rel="stylesheet" type="text/css" href="">
<script id="sap-ui-bootstrap" src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" type="text/javascript" data-sap-ui-libs="sap.ui.core,sap.ui.commons,sap.ui.table" data-sap-ui-theme="sap_goldreflection">
</script>
<script>
var airsideTableDataOriginal=
//{"genericTableModel":
[
{"columnId":"col1","WS":"WS 1","Status":0},
{"columnId":"col 2","WS":"WS 2","Status":1},
{"columnId":"col3","WS":"WS 3","Status":2},
{"columnId":"col4","WS":"WS 4","Status":3},
{"columnId":"col5","WS":"WS 5","Status":4},
];
var aColumnData = [{
columnId: "col1"
}, {
columnId: "col 2"
}, {
columnId: "col3"
}, {
columnId: "col4"
}, {
columnId: "col5"
}];
var aData = [{
"col 2": "WS 2",
col3: "WS 3",
col4: "WS 4",
col5: "WS 5"
}];
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
columns: aColumnData,
rows: aData
});
var oTable = new sap.ui.table.Table({
title: "Table column and data binding",
showNoData : true,
columnHeaderHeight : 10,
visibleRowCount: 7
});
oTable.setModel(oModel);
oTable.bindColumns("/columns", function(index, context) {
var sColumnId = context.getObject().columnId;
var tempJson=airsideTableDataOriginal;
return new sap.ui.table.Column({
id : sColumnId,
label: sColumnId,
template: new sap.ui.commons.Button({
text : {
path: sColumnId,
formatter: function(value){
if(value!=null){
var specificJson= $.grep(tempJson, function( n, i ) {
return n.columnId === sColumnId.toString() && n.WS === value.toString();
});
if(specificJson[0].Status == 1){
this.setIcon("sap-icon://accept");
this.setStyle(sap.ui.commons.ButtonStyle.Accept);
}
}
if(value === "" || value == undefined){
this.setVisible(false);
}
return value ;
}
},
}),
sortProperty: sColumnId,
filterProperty: sColumnId
});
});
oTable.bindRows("/rows");
oTable.placeAt("content");
</script>
</head>
<body class="sapUiBody" id="body" role="application">
<div id="content"></div>
</body>
</html>
As per the above code there is space between col 2 which gives error "col 2" is not a valid ID.. Here is the bin. But when I replace col 2 with col2 it works fine. But in real time I get spaces in data so how to fix it so that it would work with spaces also.
I would guess, that the error comes from the invalid ID of the Column object: id : sColumnId, (the first line after return new sap.ui.table.Column({) and not from the binding.
Like Mark said in his comment Element IDs cannot contain spaces. But the ID is not visible to the User and you can just replace the spaces of the Column.id while assigning or you can skip the id assignment at all to get automaticaly generated ids.
A client who demands spaces in their ID's I would 1) definitely steer clear from, and if that's not possible, 2) educate them that their "requirement" is utter [...]
Nevertheless, I would simply replace the spaces with underscores (it's really simple Javascript):
airsideTableDataOriginal.forEach(function(obj) {
obj.columnId = obj.columnId.replace(/ /g,"_");
});
aColumnData.forEach(function(obj) {
obj.columnId = obj.columnId.replace(/ /g,"_");
});
aData.forEach(function(obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (~property.indexOf(" ")) {
var newProperty = property.replace(/ /g,"_");
obj[newProperty] = obj[property];
delete obj[property];
}
}
}
});

Bind results of client side calculations to control (e.g. chart)

If the source for my chart in SAP UI5 is not a model loaded from a server or file, but the result of some calculations (groupings/maths) based on an existing model, how do I correctly bind it to the chart control and use the data?
You first create the outcome of the calculation. Then you transfer it in a new JSON model and use the setData function to pass the results.
Then you bind the control to the new JSON model. I try to make up some dummy code probably located in your controller:
var data = modelWithRawData.getData();
calculationOutput = doComplicatedCalculation(data);
var calculationModel = new sap.ui.model.json.JSONModel(calculationOutput)
myView.setModel(calculationModel, "calculationModel");
And in the path of your bindings you now need to reference the modelName. Eg in an xmlView:
<Chart data="{calculationModel>/PathToRelevantData}">
<!-- more xml -->
Here's a working example using the sap.viz library:
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />
<script src="resources/sap-ui-core.js" id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons,sap.ui.layout,sap.ui.ux3,sap.ui.table,sap.m,sap.viz"
data-sap-ui-theme="sap_goldreflection">
</script>
<script>
var oModel = new sap.ui.model.json.JSONModel({
businessData : [
{text: "A", value: 100},
{text: "B", value: 200},
{text: "C", value: 300}
]
});
//DO SOME ADVANCE CALCULATION WITH THE JSON DATA...
var data = oModel.getData();
data.businessData[0].value += 30;
data.businessData[1].value = data.businessData[1].value * 2;
data.businessData[2].value = data.businessData[2].value - 100;
//END OF SOME ADVANCE CALCULATION WITH THE JSON DATA...
var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions : [{axis : 1, name : 'Text', value : "{text}"}],
measures : [{name : 'Value', value : '{value}'},
],
data : {path : "/businessData"}
});
var oBarChart = new sap.viz.ui5.Bar({
title : {
visible : true,
text : 'My bar chart'
},
dataset : oDataset
});
// attach the model to the chart and display it
oBarChart.setModel(oModel);
oBarChart.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
Hope this helps.

How to get select's value in jqGrid when using <select> editoptions on a column

I have a couple of columns in jqGrid with edittype="select". How can I read the option value of the value currently selected in a particular row?
e.g.: When I provide the following option, how do I get "FE" for FedEx, etc.
editoption: { value: “FE:FedEx; IN:InTime; TN:TNT” }
getRowData() for the rowId/cellname returns only the text/displayed component of the select.
If I set a "change" data event on the column, the underlying fires change events only on mouse clicks, and not keyboard selects (there's numerous references to generic selects and mouse/keyboard issues).
Bottomline, when a new value is selected, I need to know the option value at the time of the change, and also prior to posting to the server.
You have to set the formatter of the column to 'select'
Example from the wiki:
colModel : [ {name:'myname',
edittype:'select', formatter:'select',
editoptions:{value:"1:One;2:Two"}} ...
]
See more here jqgridwiki
I was having the same problem and this worked like a charm
I just solved this question by using setting JqGrid unformat option and use the following function for unformatting cell value.
function Unformat_Select(cellvalue, options, cellobject)
{
var unformatValue = '';
$.each(options.colModel.editoptions.value, function (k, value)
{
if (cellvalue == value)
{
unformatValue = k;
}
});
return unformatValue;
}
The above method will be called everytime when grid need cell data like when you call "getRowData" method. However, my function only support key-paired value edit option. You need to change your data like the following pattern.
editoption:
{
value:
{
FE:'FedEx',
IN:'InTime',
TN:'TNT'
}
}
For more information about unformat option, you can see at the following link.
JqGrid Wiki - Custom Formatter
PS. It's possible to modify my function to support client-side dropdownlist value. But I think it's impossible to apply this function for server-side dropdownlist value.
Update
In the latest jqGrid 3.8.1, I just found some bug when user cancel editing row(or programmatically call "restoreRow" method), jqGrid will create label by using key of data (instead of value of data). I create the following function to fix this issue. For use this, you must it as custom formatter function of this column. This function maps cell value to value of list by comparing key or value.
function JqGridInlineEditor_SelectFormatter(cellvalue, options, rowObject)
{
var temp = '';
$.each(options.colModel.editoptions.value, function (key, value)
{
if (cellvalue == key || cellvalue == value)
{
temp = value;
return false;
}
});
return temp;
}
So, you can send key or value as column data to be rendered by the above custom formatter.
If in case you have requirement where each row has dropdown and it has values like
FE:'FedEx',
IN:'InTime',
TN:'TNT'
Now instead of saving the data to backend on dropdown change event;you want to save data on "Save" button click at row level but want to save dropdwon selected value (TN) not display text(TNT). You can create another hidden field to set selected country code on inline editing of dropdown. Here when user exit after cell inline editing afterSaveCell method will be called and you can set it as mentioned in below code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>http://stackoverflow.com/q/9655426/315935</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/redmond/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/css/ui.jqgrid.css" />
<style type="text/css">
html, body { font-size: 75%; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/js/jquery.jqGrid.src.js"></script>
<script type="text/javascript">
//<![CDATA[
/*global $ */
/*jslint devel: true, browser: true, plusplus: true, nomen: true, unparam: true */
$(document).ready(function () {
'use strict';
var listOptions = "CN:Canada; US:United States; FR:France; IN:India";
var mydata = [{
name: "Toronto",
country: "CN",
continent: "North America",
countrycode: "CN"
}, {
name: "New York City",
country: "US",
continent: "North America",
countrycode: "US"
}, {
name: "Silicon Valley",
country: "US",
continent: "North America",
countrycode: "US"
}, {
name: "Paris",
country: "FR",
continent: "Europe",
countrycode: "FR"
}, {
name: "Pune",
country: "IN",
continent: "Asia",
countrycode: "IN"
}]
$("#gvManageMapping").jqGrid({
data: mydata,
datatype: "local",
colNames: ["Name", "Country", "Continent", "countrycode"],
colModel: [{
name: 'name',
index: 'name',
editable: false,
},
{
name: 'country',
index: 'country',
editable: true, edittype: "select", formatter: 'select', editoptions: {
value: listOptions,
}, editrules: { required: true, integer: false }, formatter: "select"
},
{
name: 'continent',
index: 'continent',
editable: false,
},
{
name: 'countrycode',
index: 'countrycode',
editable: false
}],
afterSaveCell: function (rowid, cellname, value) {
var selectedCountryCode, $this;
if (cellname === 'country') {
$this = $(this);
selectedCountryCode = $this.jqGrid("getCell", rowid, 'country');
$this.jqGrid("setCell", rowid, 'countrycode', selectedCountryCode);
}
},
pager: '#pager',
'cellEdit': true,
'cellsubmit': 'clientArray',
editurl: 'clientArray'
});
});
//]]>
</script>
</head>
<body>
<table id="gvManageMapping"><tr><td /></tr></table>
<div id="pager"></div>
</body>
</html>
The documentation for getRowData states:
Do not use this method when you editing the row or cell. This will return the cell content and not the actuall value of the input element
Is the row still being edited when you call getRowData()?
Update
Agreed, jqGrid does not handle <select> very well. In my application I actually was able to get around this by not specifying an edit option (meaning, key/value were both "FedEx"); the translation to ID is then done on the server. This is not the right way to code this, but it worked well enough for my needs at the time.