Implementing a tile layout with a component

I am trying to create a tile based layout using a component in openui5. I am basing my code on the TileContainer example on the ui5 site I visited

Edit: The component works, but the TileContainer / StandardTile code won't show. If I create a view directly from Index.html, ignoring the component, the tiles are displayed. If I use a Page control to wrap them in a view it doesn't work. However, the List control displays with a component, but not if I also use a Page control to wrap the list.

Page controls and tiles are not compatible?

I replaced my code with my current version, it should be better to help others as it now more directly focuses on the problem of using a component with a Tile view instead of the simpler errors I had before now being resolved.

Edit: The issue was solved by using the control in XML view. The tiles are now displayed correctly.

My index.html:

<!DOCTYPE HTML>
<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.m"
    data-sap-ui-theme="sap_bluecrystal"
    data-sap-ui-xx-bindingSyntax="complex">
</script>

<style >
    body, html, #content {
        height:100%;
    }
</style>

<script>
    sap.ui.localResources("my_info");
    sap.ui.localResources("view");
    sap.ui.localResources("component");
    sap.ui.localResources("data");

    var oCompCont1 = new sap.ui.core.ComponentContainer("CompCont1", {
        name: "component"
    });
    oCompCont1.placeAt("content");
</script>
</head>

<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>

      

My Component.js:

jQuery.sap.require("sap.ui.core.UIComponent");
jQuery.sap.require("sap.ui.core.mvc.ViewType");
jQuery.sap.require("sap.m.Page");
jQuery.sap.declare("component.Component");

sap.ui.core.UIComponent.extend("component.Component", {

metadata: {
properties: {
  text: "string"
 }
}
});

component.Component.prototype.createContent = function(){
  this.oView = sap.ui.xmlview({id:"view1", viewName:"view.Home"});
  return this.oView;
};

      

My Component.json:

{
"name": "component.Component",
"version": "0.1.0",
"description": "Tiles Component"
}

      

My Home.view.xml:

<mvc:View
height="100%"
controllerName="view.Home"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">

//ensure you use the App control, this fixed the problem for me.
<App>
<Page
  showHeader="false"
  enableScrolling="false" >

 <TileContainer
  id="container"
  tiles="{/TileCollection}">
  <StandardTile
   icon="sap-icon://{icon}"
   title="{title}" />
 </TileContainer>
</Page>
</App>
</mvc:View>

      

My Home.controller.js:

sap.ui.controller("view.Home", {

onInit : function (evt) {
 var sPath = jQuery.sap.getModulePath("data", "/tiles.json");
 var oModel = new sap.ui.model.json.JSONModel(sPath);
 this.getView().setModel(oModel);
 }
});

      

My tiles.json:

{
"TileCollection" : [
{
  "icon" : "document-text",
  "title" : "Personal Data"
},

{
  "icon" : "addresses",
  "title" : "Address Data"
},

{
  "icon" : "simple-payment",
  "title" : "Bank Details"
},

{
  "icon" : "car-rental",
  "title" : "Vehicle Details"
},

{
  "icon" : "study-leave",
  "title" : "Training and Qualifications"
}
]
}

      

Thanks in advance.

+3


source to share


1 answer


As discussed in the comments above and in line with this question, you should wrap yours sap.m.TileContainer

in the sap.m.App

following:

<mvc:View height="100%" controllerName="sap.ui.demo.Onepage.view.App"
    xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
<App>
    <Page
      showHeader="false"
      enableScrolling="false" >

     <TileContainer
      id="container"
      tiles="{/TileCollection}">
          <StandardTile icon="sap-icon://{icon}" title="{title}" />
     </TileContainer>
    </Page>
</App>

      



sap.m.App

Can of course be implemented in a separate view / controller file and act as the "root" view / controller.

+4


source







All Articles