I am having a table with columns as below:
<Table id="table2" visibleRowCount="5" rows="{
path: '/ProductCollection',
sorter: {path: 'serialId', descending: false}}">
<columns>
<Column width="50px">
<m:Text text="Employee ID" />
<template>
<m:Text text="{employeeId}" wrapping="false" />
</template>
</Column>
<Column width="200px">
<m:Text text="EmployeeName" />
<template>
<m:Text text="{employeeName}" wrapping="false" />
</template>
</Column>
</columns>
</Table>
And JSON Data is :
var oData = {
ProductCollection: [
{
employeeId: "1"
employeeName:"xyz"
},
{
employeeId: "1"
employeeName:"xyz"
},
{
employeeId: "1"
employeeName:"xyz"
}
]
};
And i have tried binding as :
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(ProductCollection);
this.getView().setModel(oModel);
I am getting the data but into model but unable to display values in table getting empty rows.I am facing problem in binding(xml view)any guiding links or a solution would be much helpful , TIA
<mvc:View controllerName="reg.cmdd.Consumer.controller.Home" xmlns="sap.ui.table" xmlns:mvc="sap.ui.core.mvc" xmlns:u="sap.ui.unified"
xmlns:c="sap.ui.core" xmlns:m="sap.m" height="100%">
<m:Page showHeader="false" enableScrolling="false" class="sapUiContentPadding">
<m:content>
<Table id="table2" visibleRowCount="5" rows="{ path: '/ProductCollection', sorter: {path: 'serialId', descending: false}}">
<columns>
<Column width="50px">
<m:Text text="Employee ID"/>
<template>
<m:Text text="{employeeId}" wrapping="false"/>
</template>
</Column>
<Column width="200px">
<m:Text text="EmployeeName"/>
<template>
<m:Text text="{employeeName}" wrapping="false"/>
</template>
</Column>
</columns>
</Table>
</m:content>
</m:Page>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("reg.cmdd.Consumer.controller.Home", {
onInit: function () {
var oData = {
ProductCollection: [{
employeeId: "1",
employeeName: "xyz"
}, {
employeeId: "1",
employeeName: "xyz"
}, {
employeeId: "1",
employeeName: "xyz"
}
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
this.getView().setModel(oModel);
}
});
});
Your code is fine, the problem must be elsewhere
EDIT:
check this line:
oModel.setData(ProductCollection);
it should be
oModel.setData(oData);
I would like to list down all the information like in the sap.m.ObjectListItem but with sap.m.CustomListItem, see the screenshot attached. How do I achieve that? any working example?
This is what I have done so far, still a long way to go:
var oListTemplate = new sap.m.CustomListItem({
content: [
new sap.m.VBox({
items: [
new sap.m.Text({
text: "{nct_id}"
}),
new sap.m.HBox({
justifyContent: "SpaceBetween",
items: [
new sap.m.Label({
textAlign: sap.ui.core.TextAlign.Left,
text: "{title}",
}).addStyleClass("Text_Big font_bold"),
new sap.m.FormattedText({
textAlign: sap.ui.core.TextAlign.Right,
htmlText: "{condition_summary}"
}),
]
}).addStyleClass("sapUiTinyMargin")
]
}).addStyleClass("sapUiTinyMargin"),
],
type: sap.m.ListType.Active,
press: function() {
alert("Clicked the list item");
}
Here is what you are looking for, hope this help you.
As #Erch suggested better to use XML view.
JS
var oListTemplate = new sap.m.CustomListItem({
content: [
new sap.m.HBox({
items: [
new sap.m.FlexBox({
items: [
new sap.m.VBox({
width: "80%",
items: [
new sap.m.ObjectIdentifier({ title: "", text: "", titleActive: "false" }),
new sap.m.Label({ text: "" }),
new sap.m.Label({ text: "" })
],
layoutData: new sap.m.FlexItemData({ growFactor: 3 })
})
new sap.m.VBox({
width: "100px",
items: [
new sap.m.Label({ text: "" }),
new sap.m.Label({ text: "" }),
new sap.m.ObjectStatus({ text: "", state: "Success" })
],
layoutData: new sap.m.FlexItemData({ growFactor: 1 })
})
],
width: "100%",
alignItems: "Start"
})
],
width: "100%",
fitContainer: "true"
}).addStyleClass("sapUiTinyMargin"),
],
type: sap.m.ListType.Active,
press: function() {
alert("Clicked the list item");
})
}
XML
<List>
<items>
<CustomListItem>
<HBox width="100%" fitContainer="true">
<FlexBox width="100%" alignItems="Start" class="sapUiTinyMargin">
<items>
<VBox width="80%">
<ObjectIdentifier title="" text="" titleActive="false" />
<Label text="" />
<Label text="" />
<layoutData>
<FlexItemData growFactor="3" />
</layoutData>
</VBox>
<VBox width="100px" class="sapUiTinyMarginBegin">
<items>
<Label text="" />
<Label text="" />
<ObjectStatus text="Product Shipped" state="Success" />
</items>
<layoutData>
<FlexItemData growFactor="1" />
</layoutData>
</VBox>
</items>
</FlexBox>
</HBox>
</CustomListItem>
</items>
</List>
Somehow my filter update through the function onSearch is not updating the view. The initial Filter in the XML View is working fine. Also when sIaNr is empty the aFilter = [] is working as I'm seeing all results. But when sIaNr is not empty this part is called and the filter is not working:
aFilter.push(new Filter("raufnr", FilterOperator.EQ, sIaNr))
this is my Code
ZCATS_TESTJ.json
{
"d": {
"results": [{
"status": "30",
"skostl": "0001",
"catshours": "2.50",
"ktext": "test1",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "xx123",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025"
}, {
"status": "30",
"skostl": "0001",
"catshours": "8.00",
"ktext": "test2",
"counter": "000002919281",
"mandt": "101",
"pernr": "1234",
"usrid": "xx123",
"workdate": "\/Date(1441065600000)\/",
"raufnr": "0815"
}, {
"status": "30",
"skostl": "0001",
"catshours": "8.00",
"ktext": "test1",
"counter": "000002919281",
"mandt": "101",
"pernr": "00015822",
"usrid": "xx123",
"workdate": "\/Date(1441065600000)\/",
"raufnr": "6000007"
}]
}
}
List.view
<mvc:View
controllerName="sap.ui.bookedTimes.wt.controller.List"
id="listview"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns:fb="sap.ui.comp.filterbar"
xmlns:core="sap.ui.core"
xmlns="sap.m">
<Table id="exportTable" inset="false" growing="true" growingThreshold="700" visible="true"
items="{
path : 'view>/d/results',
filters : [
{ path : 'raufnr', operator : 'EQ', value1 : '6000007'}
]
}">
<headerToolbar>
<OverflowToolbar>
<ToolbarSpacer />
<Button icon="sap-icon://excel-attachment" press="onExport"/>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column>
<Text text="IA-Nummer" />
</Column>
<Column>
<Text text="Bezeichnung" />
</Column>
<Column>
<Text text="Datum" />
</Column>
<Column hAlign="End">
<Text text="Zeit" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{view>raufnr}" />
<Text id="tText" text="{view>ktext}" />
<Text text="{path: 'view>workdate', type: 'sap.ui.model.type.Date', formatOptions: { pattern: 'dd.MM.yyyy' } }" />
<Text text="{view>catshours}" />
</cells>
</ColumnListItem>
</items>
</Table>
List.controller
sap.ui.define([
'jquery.sap.global',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel',
'sap/ui/core/util/MockServer',
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator",
"sap/ui/model/FilterType"
// 'sap/ui/export/Spreadsheet'
], function(jQuery, Controller, JSONModel, Filter, FilterOperator, FilterType) {
"use strict";
return Controller.extend("sap.ui.bookedTimes.wt.controller.List", {
onInit : function () {
//Get Model
var jModel = this.getOwnerComponent().getModel("zCatsTestJ");
var that = this;
//after Model is loaded transform Date
jModel.attachRequestCompleted(function() {
//var oViewModel= new JSONModel(jModel);
for (var i = 0; i< jModel.oData.d.results.length; i++){
var sJsonDate = jModel.getProperty("/d/results/" + [i] + "/workdate");
//Json Date in Datumsformat umwandeln
var sNumber = sJsonDate.replace(/[^0-9]+/g,'');
var iNumber = sNumber * 1; //trick seventeen
var oDate = new Date(iNumber);
jModel.setProperty("/d/results/" + [i] + "/workdate", oDate);
}
//update the model with new Date format
that.getView().setModel(jModel, "view");
});
},
onSearch: function(oEvent) {
// build filter array
var aFilter = [];
var oParams = oEvent.getParameter("selectionSet");
var sIaNr = oParams[0].getValue();
var oList = this.getView().byId("exportTable");
var oBinding = oList.getBinding("items");
if (sIaNr) {
aFilter.push(new Filter("raufnr", FilterOperator.EQ, sIaNr));
}
//filter binding
oBinding.filter(aFilter, FilterType.Application);
}
});
});
any help would be greatly appreciated. Thanks
Delete 'sap/ui/core/util/MockServer' in the define part.
I'm using PlanningCalendar App to show the workers schedule.
But what I also need is, after I click on the worker (for example 'Carlos Pinho') his data (name and role) appear on the TextBox from the SimpleForm (red arrow)
Controller:
sap.ui.define([
'jquery.sap.global',
'sap/m/StandardListItem',
'sap/m/MessageToast',
'sap/ui/core/mvc/Controller',
'sap/m/Label',
'sap/m/Text',
'sap/m/TextArea',
'sap/ui/model/json/JSONModel'], function(jQuery, StandardListItem, MessageToast, Controller, Label, Text, TextArea, JSONModel) {
"use strict";
return Controller.extend("zapp_rej_absence.controller.Main", {
onInit: function() {
//this.getView().byId() //Para definir o que aparece na combo box
// create model
var oModel = new JSONModel();
oModel.setData({
startDate: new Date("2017", "4", "26", "8", "0"),
people: [{
pic: "sap-icon://employee", //Foto do Funcionario
name: "Carlos Pinho", //Nome do Funcionario
role: "Logística", //Area do Funcionario
appointments: [{
start: new Date("2017", "4", "29", "12", "0"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "4", "29", "14", "0"),
title: "Reunião de Equipa",
info: "Sala A06",
type: "Type01", //Cor do Evento
pic: "sap-icon://manager",
tentative: false
}, {
start: new Date("2017", "5", "10", "0", "0"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "5", "16", "23", "59"),
title: "Férias",
info: "Maldivas",
pic: "sap-icon://flight",
type: "Type04", //Cor do Evento
tentative: false
}],
headers: [{
start: new Date("2017", "4", "29", "08", "0"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "4", "29", "10", "0"),
title: "Privado",
type: "Type05"
}]
}, {
pic: "sap-icon://employee", //Foto do Funcionario
name: "Joaquim Agostinho", //Nome do Funcionario
role: "Financeira", //Area do Funcionario
appointments: [{
start: new Date("2017", "4", "29", "08", "30"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "4", "29", "09", "30"),
title: "Reunião",
pic: "sap-icon://world",
type: "Type02", //Cor do Evento
tentative: false
}, {
start: new Date("2017", "4", "30", "10", "0"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "4", "30", "12", "0"),
title: "Reunião de Equipa",
info: "Sala 1",
type: "Type01", //Cor do Evento
pic: "sap-icon://manager",
tentative: false
}, {
start: new Date("2017", "4", "30", "12", "30"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "4", "30", "13", "30"),
title: "Almoço",
type: "Type03", //Cor do Evento
pic: "sap-icon://meal",
tentative: true
}],
headers: [{
start: new Date("2017", "4", "29", "8", "0"), //[Ano, Meses (cujo a ordem é Janeiro ->0), Dia, Horas, Minutos]
end: new Date("2017", "4", "29", "10", "0"),
title: "Lembrete",
type: "Type06" //Cor do Evento
}]
}]
});
this.getView().setModel(oModel);
},
//Dialog do botão aceitar
onMessageSuccessDialogPress: function(oEvent) {
var dialog = new Dialog({
title: 'Successo',
type: 'Message',
state: 'Success',
content: new Text({
text: "Foi aprovado com sucesso."
}),
beginButton: new Button({
text: 'OK',
press: function() {
MessageToast.show('Pedido Aprovado');
dialog.close();
}
}),
afterClose: function() {
dialog.destroy();
}
});
dialog.open();
},
onMessageWarningDialogPress: function(oEvent) {
var dialog = new Dialog({
title: 'Aviso',
type: 'Message',
state: 'Warning',
content: new Text({
text: 'Tem a certeza que quer rejeitar este pedido?'
}),
beginButton: new Button({
text: 'Sim',
press: function() {
dialog.close();
var dialog1 = new Dialog({
title: 'Confirmação',
type: 'Message',
content: [
new Label({
text: 'Tem a certeza que pretende rejeitar o pedido?',
labelFor: 'submitDialogTextarea'
}),
new TextArea('submitDialogTextarea', {
liveChange: function(oEvent) {
var sText = oEvent.getParameter('value');
var parent = oEvent.getSource().getParent();
parent.getBeginButton().setEnabled(sText.length > 0);
},
width: '100%',
placeholder: 'Adicionar nota (obrigatória)'
})
],
beginButton: new Button({
text: 'Submit',
enabled: false,
press: function() {
MessageToast.show('Pedido Rejeitado');
dialog1.close();
}
}),
endButton: new Button({
text: 'Cancel',
press: function() {
dialog1.close();
}
}),
afterClose: function() {
dialog1.destroy();
}
});
dialog1.open();
}
}),
endButton: new Button({
text: 'Não',
press: function() {
dialog.close();
}
}),
afterClose: function() {
dialog.destroy();
}
});
dialog.open();
},
onSubmitDialog: function() {
var dialog = new Dialog({
title: 'Confirm',
type: 'Message',
content: [
new Label({
text: 'Are you sure you want to submit your shopping cart?',
labelFor: 'submitDialogTextarea'
}),
new TextArea('submitDialogTextarea', {
liveChange: function(oEvent) {
var sText = oEvent.getParameter('value');
var parent = oEvent.getSource().getParent();
parent.getBeginButton().setEnabled(sText.length > 0);
},
width: '100%',
placeholder: 'Add note (required)'
})
],
beginButton: new Button({
text: 'Submit',
enabled: false,
press: function() {
var sText = sap.ui.getCore().byId('submitDialogTextarea').getValue();
MessageToast.show('Note is: ' + sText);
dialog.close();
}
}),
endButton: new Button({
text: 'Cancel',
press: function() {
dialog.close();
}
}),
afterClose: function() {
dialog.destroy();
}
});
dialog.open();
},
onMessageDialogPress: function(oEvent) {
var dialog = new Dialog({
title: 'Meses Aprovados',
icon: 'sap-icon://calendar',
type: 'Message',
content: new Text({
text: 'A ideia é aparecer os meses todos em RadioButtons'
}),
beginButton: new Button({
text: 'OK',
press: function() {
dialog.close();
}
}),
endButton: new Button({
text: 'Cancelar',
press: function() {
dialog.close();
}
}),
afterClose: function() {
dialog.destroy();
}
});
dialog.open();
},
handlePopoverPress: function(oEvent) {
// create popover
if (!this._oPopover) {
this._oPopover = sap.ui.xmlfragment("zapp_rej_absence.view.Popover", this);
this.getView().addDependent(this._oPopover);
this._oPopover.bindElement("/ProductCollection/0");
}
// delay because addDependent will do a async rerendering and the actionSheet will immediately close without it.
var oButton = oEvent.getSource();
jQuery.sap.delayedCall(0, this, function() {
this._oPopover.openBy(oButton);
});
},
//---------------------------------------------------------Eventos
handleAppointmentSelect: function(oEvent) {
var oAppointment = oEvent.getParameter("appointment"); //Selecçao do Evento
if (oAppointment) {
alert("Evento Selecionado: " + oAppointment.getTitle());
} else {
var aAppointments = oEvent.getParameter("appointments");
var sValue = aAppointments.length + " Eventos Selecionados";
alert(sValue);
}
}
}); });
XML:
<mvc:View controllerName="zapp_rej_absence.controller.Main" xmlns:html="http://www.w3.org/1999/xhtml" displayBlock="true" xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc" xmlns:unified="sap.ui.unified" xmlns:f="sap.ui.layout.form">
<Page title="Aprovação de Férias/Ausências" enableScrolling="true">
<Panel class="sapUiSmallMargin" width="auto">
<PlanningCalendar id="PC1" startDate="{path: '/startDate'}" rows="{path: '/people'}" appointmentsVisualization="Filled"
appointmentSelect="handleAppointmentSelect" showEmptyIntervalHeaders="false" viewKey="One Month">
<toolbarContent>
<Title text="Calendário" titleStyle="H4"/>
<ToolbarSpacer/>
<SearchField width="300px" placeholder="Procurar..."/>
<Button icon="sap-icon://legend" press="handlePopoverPress"/>
</toolbarContent>
<rows>
<PlanningCalendarRow icon="{pic}" title="{name}" text="{role}" appointments="{appointments}" intervalHeaders="{headers}">
<appointments>
<unified:CalendarAppointment startDate="{start}" endDate="{end}" icon="{pic}" title="{title}" text="{info}" type="{type}"
tentative="{tentative}"></unified:CalendarAppointment>
</appointments>
<intervalHeaders>
<unified:CalendarAppointment startDate="{start}" endDate="{end}" icon="{pic}" title="{title}" type="{type}"></unified:CalendarAppointment>
</intervalHeaders>
</PlanningCalendarRow>
</rows>
</PlanningCalendar>
<f:SimpleForm id="SimpleFormDisplay354" class="sapUiLargeMarginTop" width="auto" editable="false" layout="ResponsiveGridLayout"
title="Informações do Colaborador" labelSpanXL="3" labelSpanL="3" labelSpanM="3" labelSpanS="12" adjustLabelSpan="false" emptySpanXL="4"
emptySpanL="4" emptySpanM="4" emptySpanS="0" columnsXL="1" columnsL="1" columnsM="1" singleContainerFullSize="false">
<f:content>
<Label text="Nome" width="100%" design="Bold"/>
<Text text="{Name}" width="100%"/>
<!--Depois ir buscar estes dados à BD-->
<Label text="Equipa" width="100%" design="Bold"/>
<Text text="{Street} {HouseNumber}" width="100%"/>
<!--Depois ir buscar estes dados à BD-->
<Label text="Total de Férias" width="100%" design="Bold"/>
<Text text="{ZIPCode} {City}" width="100%"/>
<!--Depois ir buscar estes dados à BD-->
<Label text="Country" width="100%" design="Bold"/>
<Text text="{Country}" width="100%"/><!--Depois ir buscar estes dados à BD--></f:content>
</f:SimpleForm>
</Panel>
<footer>
<Toolbar>
<Button icon="sap-icon://past" text="Meses Aprovados" type="Emphasized" press="onMessageDialogPress"/>
<ToolbarSpacer/>
<Button icon="sap-icon://accept" text="Aprovar" type="Accept" press="onMessageSuccessDialogPress"/>
<Button icon="sap-icon://sys-cancel-2" text="Rejeitar" type="Reject" press="onMessageWarningDialogPress" />
</Toolbar>
</footer>
</Page>
Thanks in advance for your help.
I used the binding context of selected row and bound it to the form below and it worked.
Below is the working code and steps:
Add "Row Selection Event" to planning calender.
<PlanningCalendar id="PC1" startDate="{path: '/startDate'}" rows="{path: '/people'}"
appointmentsVisualization="Filled"
appointmentSelect="handleAppointmentSelect" showEmptyIntervalHeaders="false" viewKey="One Month"
rowSelectionChange="onRowSelection">
Step 2: Find the binding Context of selected row and bind it to the form:
onRowSelection: function(oEvent) {
var oForm = this.byId('SimpleFormDisplay354');
var oBindingContext = oEvent.getSource().getSelectedRows()[0].getBindingContext();
oForm.setBindingContext(oBindingContext);
}
Step 3: Bind correct Properties in the form:
<f:SimpleForm id="SimpleFormDisplay354" class="sapUiLargeMarginTop" width="auto" editable="false" layout="ResponsiveGridLayout"
title="Informações do Colaborador" labelSpanXL="3" labelSpanL="3" labelSpanM="3" labelSpanS="12" adjustLabelSpan="false" emptySpanXL="4"
emptySpanL="4" emptySpanM="4" emptySpanS="0" columnsXL="1" columnsL="1" columnsM="1" singleContainerFullSize="false">
<f:content>
<Label text="Nome" width="100%" design="Bold"/>
<Text text="{name}" width="100%"/>
<!--Depois ir buscar estes dados à BD-->
<Label text="Role" width="100%" design="Bold"/>
<Text text="{role}" width="100%"/>
</f:content>
</f:SimpleForm>
Let me know if this works for you.