cancel
Showing results for 
Search instead for 
Did you mean: 

sap fiori --> full screen application template --> how n where to do Odata.read and how to get value from it

former_member182645
Participant
0 Kudos

hi all

I am using fiori full screen tamplate in webide

which generate main,master,detail view.

i want show date wise count with date picker,

how to collect return value send by

oModel.read("/CountSet", {filters : [


new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730");


]});


and


how to show result on same page?



Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

var that = this;


oModel.read("/CountSet", {filters : [

new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730");

],


success: function (oEvent) {

     that.byId("DATPICKER_ID").setDateValue( oEvent.result.DATE_FIELD );

}

});

former_member182645
Participant
0 Kudos

hi maksim

unable replicate value in ui.

this is my component.js

// define a root UI component that exposes the main view

  1. jQuery.sap.declare("mainpage.Component");
  2. jQuery.sap.require("sap.ui.core.UIComponent");
  3. jQuery.sap.require("sap.ui.core.routing.History");
  4. jQuery.sap.require("sap.m.routing.RouteMatchedHandler");

  1. sap.ui.core.UIComponent.extend("mainpage.Component", {

                metadata: {

                                "name": "zrs_count",

                                "version": "1.1.0-SNAPSHOT",

                                "library": "mainpage",

                                "includes": ["css/fullScreenStyles.css"],

                                "dependencies": {

                                                "libs": ["sap.m", "sap.ui.layout"],

                                                "components": []

                                },

                                "config": {

                                                resourceBundle: "i18n/messageBundle.properties",

                                                serviceConfig: {

                                                                name: "ZRSCOUNT_SRV",

                                                                serviceUrl: "/sap/opu/odata/sap/ZRSCOUNT_SRV/"

                                                }

                                },

                                routing: {

                                                // The default values for routes

                                                config: {

                                                                "viewType": "XML",

                                                                "viewPath": "mainpage.view",

                                                                "targetControl": "fioriContent", // This is the control in which new views are placed

                                                                "targetAggregation": "pages", // This is the aggregation in which the new views will be placed

                                                                "clearTarget": false

                                                },

                                                routes: [

                                                                {

                                                                                //pattern: "{entity}",

                                                                                pattern : "",

                                                                                name: "main",

                                                                                view: "Master"

                                                                               

                                                                },

                                                                {

                                                                                name: "details",

                                                                                view: "Details",

                                                                                pattern: "{entity}"

                                                                }

                                                ]

                                }

                },

                /**

                 * Initialize the application

                 *

                 * @returns {sap.ui.core.Control} the content

                 */

                createContent: function() {

                                var oViewData = {

                                                component: this

                                };

                                return sap.ui.view({

                                                viewName: "mainpage.view.Main",

                                                type: sap.ui.core.mvc.ViewType.XML,

                                                viewData: oViewData

                                });

                },

                init: function() {

                                // call super init (will call function "create content")

                                sap.ui.core.UIComponent.prototype.init.apply(this, arguments);

                                // always use absolute paths relative to our own component

                                // (relative paths will fail if running in the Fiori Launchpad)

                                var sRootPath = jQuery.sap.getModulePath("mainpage");

                                // The service URL for the oData model

                                var oServiceConfig = this.getMetadata().getConfig().serviceConfig;

                                var sServiceUrl = oServiceConfig.serviceUrl;

                                // the metadata is read to get the location of the i18n language files later

                                var mConfig = this.getMetadata().getConfig();

                                this._routeMatchedHandler = new sap.m.routing.RouteMatchedHandler(this.getRouter(), this._bRouterCloseDialogs);

                                // create oData model

                                this._initODataModel(sServiceUrl);

                                // set i18n model

                                var i18nModel = new sap.ui.model.resource.ResourceModel({

                                                bundleUrl: [sRootPath, mConfig.resourceBundle].join("/")

                                });

                                this.setModel(i18nModel, "i18n");

                                // initialize router and navigate to the first page

                                this.getRouter().initialize();

                },

                exit: function() {

                                this._routeMatchedHandler.destroy();

                },

                // This method lets the app can decide if a navigation closes all open dialogs

                setRouterSetCloseDialogs: function(bCloseDialogs) {

                                this._bRouterCloseDialogs = bCloseDialogs;

                                if (this._routeMatchedHandler) {

                                                this._routeMatchedHandler.setCloseDialogs(bCloseDialogs);

                                }

                },

                // creation and setup of the oData model

                _initODataModel: function(sServiceUrl) {

                                jQuery.sap.require("mainpage.util.messages");

                                var oConfig = {

                                                metadataUrlParams: {},

                                                json: true,

                                                // loadMetadataAsync : true,

                                                defaultBindingMode: "TwoWay",

                                                defaultCountMode: "Inline",

                                                useBatch: true

                                };

                                //var oTable = sap.ui.getCore().byId("catalogTable");

                                var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, oConfig);

                                oModel.read("/CountSet", {

                                                filters: [new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730")]

                                });

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

                                oODataJSONModel.setData(oModel);

                                sap.ui.getCore().setModel(oODataJSONModel, "MyJSONModel");

                                this.setModel(oODataJSONModel);

                               

                               

                }

});

former_member182645
Participant
0 Kudos

this is my

master.view.xml

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

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

  controllerName="mainpage.view.Master">

  <Page id="productListPage" title="{i18n>masterTitle}" showNavButton="true" navButtonPress="onNavBack" >

  <content>

  <Table id="catalogTable" class="navTableControlLayout"

  items="{/CountSet}" 

  growing="true" growingScrollToLoad="true">

  <headerToolbar id ="catalogTable_headerToolbar">

  <Toolbar id="tableToolbar">

  <Label id="catalogTitle" text="{viewProperties>/catalogTitleText}" class="sapMH4FontSize" visible="{viewProperties>/catalogTitleVisible}" />

  <ToolbarSpacer id="toolbarSpacer" />

  <SearchField id="searchField" showRefreshButton="false"  placeholder="{i18n>masterSearchPlaceholder}"

  tooltip="{i18n>masterSearchTooltip}" search="onSearchPressed" width="{viewProperties>/searchFieldWidth}" />

  </Toolbar>

  </headerToolbar>

  <columns id ="catalogTable_columns">

  <Column id="catalogTable_col1" width="{viewProperties>/availabilityColumnWidth}" hAlign="Left">

  <header id="catalogTable_col1_header" >

  <Label id="catalogTable_col1_label" text="No Of Records" />

  </header>

  </Column>

  <Column id="catalogTable_col2" width="{viewProperties>/availabilityColumnWidth}" hAlign="Left">

  <header id="catalogTable_col2_header">

  <Label id="catalogTable_col2_label"  text="No Of Records" />

  </header>

  </Column>

  <Column id="catalogTable_col3" width="10%" minScreenWidth="Tablet"

  demandPopin="true" hAlign="Right">

  <header id="catalogTable_col3_header">

  <Label id="catalogTable_col3_label"  text="No Of Records" />

  </header>

  </Column>

  <Column id="catalogTable_col4" width="{viewProperties>/availabilityColumnWidth}" hAlign="Right">

  <header id="catalogTable_col4_header">

  <Label id="catalogTable_col4_label"  text="No Of Records" />

  </header>

  </Column>

  </columns>

  <ColumnListItem id="columnListItem" vAlign="Middle" type="Navigation"

  press="onLineItemPressed" class="navTableItemLayout">

  <cells id="columnListItem_cells">

  <Text id="columnListItem_cell_1" text="{Itemrecords}" maxLines="2" >

                        </Text>

  <Text id="columnListItem_cell_2" text="{Itemrecords}" maxLines="2" >

                        </Text>

  <ObjectNumber id="columnListItem_cell_3"

  number="{parts:[{path:'Itemrecords'}, {path:'Itemrecords'}],

  formatter: 'sap.ca.ui.model.format.AmountFormat.FormatAmountStandard'}"

  unit="{Itemrecords}"

  > 

  </ObjectNumber>

  <ObjectStatus id="columnListItem_cell_4" text="{Itemrecords}" state="None" >

  </ObjectStatus>

  </cells>

  </ColumnListItem>

  </Table>

  <DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DP4"

  value="{ path:'/dateValue', type:'sap.ui.model.type.Date', formatOptions: { pattern: 'yyyyMMdd', UTC: true, source: { pattern: 'HH:mm:ss' } }

  }"/>

  <Button id="__button0" press="onButtonPress" text="Button" width="100px"/>

  <Button id="__button1" press="onButtonCheck" text="Button" width="100px"/>

  </content>

  <footer>

  </footer>

  </Page>

</core:View>

************************

master.controller.js

jQuery.sap.require("sap.ui.core.mvc.Controller");

jQuery.sap.require("sap.ca.ui.model.format.AmountFormat");

jQuery.sap.require("sap.m.TablePersoController");

var sValue;

sap.ui.core.mvc.Controller.extend("mainpage.view.Master", {

  _oCatalog: null,

  _oResourceBundle: null,

  onInit: function() {

  this._oView = this.getView();

  var oItemTemplate = this.byId("columnListItem").clone();

  this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this._oView));

  this._oResourceBundle = this._oComponent.getModel("i18n").getResourceBundle();

  this._oRouter = this._oComponent.getRouter();

  this._oCatalog = this.byId("catalogTable");

  this._initViewPropertiesModel();

  },

  // The model created here is used to set values or view element properties that cannot be bound

  // directly to the OData service. Setting view element attributes by binding them to a model is preferable to the

  // alternative of getting each view element by its ID and setting the values directly because a JSon model is more

  // robust if the customer removes view elements (see extensibility).

  _initViewPropertiesModel: function() {

  var oViewElemProperties = {};

  oViewElemProperties.catalogTitleText = "CountSet";

  if (sap.ui.Device.system.phone) {

  oViewElemProperties.availabilityColumnWidth = "80%";

  oViewElemProperties.pictureColumnWidth = "5rem";

  oViewElemProperties.btnColHeaderVisible = true;

  oViewElemProperties.searchFieldWidth = "100%";

  oViewElemProperties.catalogTitleVisible = false;

  // in phone mode the spacer is removed in order to increase the size of the search field

  this.byId("tableToolbar").removeContent(this.byId("toolbarSpacer"));

  } else {

  oViewElemProperties.availabilityColumnWidth = "18%";

  oViewElemProperties.pictureColumnWidth = "9%";

  oViewElemProperties.btnColHeaderVisible = false;

  oViewElemProperties.searchFieldWidth = "30%";

  oViewElemProperties.catalogTitleVisible = true;

  }

  this._oViewProperties = new sap.ui.model.json.JSONModel(oViewElemProperties);

  this._oView.setModel(this._oViewProperties, "viewProperties");

  },

  onNavBack: function() {

  window.history.go(-1);

  },

  // --- List Handling

  // Handler method for the table search.

  onSearchPressed: function() {

  var sValue = this.byId("searchField").getValue();

  var oFilter = new sap.ui.model.Filter("Itemrecords",

  sap.ui.model.FilterOperator.Contains, sValue);

  var oBinding = this.byId("catalogTable").getBinding("items");

  oBinding.filter([oFilter]);

  },

  // --- Navigation

  onLineItemPressed: function(oEvent) {

  this._oRouter.navTo("details", {

  from: "main",

  entity: oEvent.getSource().getBindingContext().getPath().substr(1),

  tab: null

  });

  },

  onButtonPress: function() {

  var oConfig = {

  metadataUrlParams: {},

  json: true,

  // loadMetadataAsync : true,

  defaultBindingMode: "TwoWay",

  defaultCountMode: "Inline",

  useBatch: true

  };

  var oTable = sap.ui.getCore().byId("catalogTable");

  var sServiceUrl = "/sap/opu/odata/sap/ZRSCOUNT_SRV/";

  var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, oConfig);

  //   oModel.read("/CountSet", {

  //   filters: [new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730")]

  //   });

  // oTable.setModel(oModel.read("/CountSet('20150730'"));

  debugger;

  oModel.read("/CountSet", {

  filters: [new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730")]

  });

  this.setModel(oModel);

  //debugger;

  this._oRouter.navTo("details", {

  from: "main",

  //

  //entity: oEvent.getSource().getBindingContext().getPath().substr(1),

  entity: "CountSet('7')",

  tab: null

  });

  debugger;

  },

  onButtonCheck: function() {

  var oConfig = {

  metadataUrlParams: {},

  json: true,

  // loadMetadataAsync : true,

  defaultBindingMode: "TwoWay",

  defaultCountMode: "Inline",

  useBatch: true

  };

  var oTable = sap.ui.getCore().byId("catalogTable");

  var sServiceUrl = "/sap/opu/odata/sap/ZRSCOUNT_SRV/";

  var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, oConfig);

  oModel.read("/CountSet", {

  filters: [new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730")]

  });

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

  oODataJSONModel.setData(oModel);

  debugger;

  this._oRouter.navTo("details", {

  from: "main",

  entity: oModel.getProperty('/CountSet'),

  tab: null

  });

  },

  handleChange: function(oEvent) {

  sValue = oEvent.getParameter("value");

  }

});

former_member182645
Participant
0 Kudos

value showing on odata lavel for et_entityset

but not replicate on ui5

former_member182372
Active Contributor
0 Kudos

what are you trying to implement?

former_member182645
Participant
0 Kudos

hi maksim

i want to store odata.read result  in variable...

former_member182645
Participant
0 Kudos

like

var rtest=oData.read

but unable to get value.

former_member182372
Active Contributor
0 Kudos

i posted the code above

var that = this;


oModel.read("/CountSet", {filters : [

new sap.ui.model.Filter("Itemrecords", sap.ui.model.FilterOperator.EQ, "20150730");

],


success: function (oEvent) {

     //oEvent.results <- array holds the server result, store it in the variable, model or set array element's property to control's attribute 

}

});

0 Kudos

Clone of the question was deleted by Moderator.

Regards, Mike (Moderator)

SAP Technology RIG