Quantcast
Viewing all articles
Browse latest Browse all 2548

Smart Table - Backend and Frontend Example

Hello Fellow SCNers,

 

In this blog, I will demo the usage of Smart Table control including OData Metadata development and Front End application code.

Smart Table uses Vocabulary based annotations in OData.

 

Backend

 

Data Structure and Data preparation


Step 1: Go to SE11 and create a table as shown below.

Image may be NSFW.
Clik here to view.
Table.jpg

Step 2: Populate the data and check.

Image may be NSFW.
Clik here to view.
Data.jpg

Service Creation


Step 3: Import the highlighted vocabulary(ies) in SEGW(Project Builder Transaction). (This is a one time activity)

Image may be NSFW.
Clik here to view.
Vocab.jpg

 

Step 4: Create a Service with Vocabulary Based Annotation as

Image may be NSFW.
Clik here to view.
Serv Det 1.jpg

 

Step 5: Create an Entity - SmartTable and corresponding EntitySet. These are standard steps and I am ignoring them here, though I have attached screenshot of the same.

Image may be NSFW.
Clik here to view.
Serv Det 2.jpg

 

Properties -

Image may be NSFW.
Clik here to view.
Serv Det 3.jpg

Step 6: Import the vocabulary in the Service as -

Image may be NSFW.
Clik here to view.
Import Vocab.jpg

 

Step 7: Create the Line Item Annotation which is the most important one for Smart table as it will help the UI5 framework to create table structure.

Choose the line item column and then click on Create Annotation.

Image may be NSFW.
Clik here to view.
Line Item.jpg

Step 8: Click on 'Append Row/Create'

Image may be NSFW.
Clik here to view.
Line Item 2.jpg

Step 9: Choose the highlighted type for property

Image may be NSFW.
Clik here to view.
Line Item 3.jpg

 

Step 10: One column is created as shown below -

Image may be NSFW.
Clik here to view.
Line Item 4.jpg

Do the above step for all 4 columns.

 

Step 11: Now the service will look like -

 

Image may be NSFW.
Clik here to view.
Proj 1.jpg

 

Step 12: Implement the Getter for Smart Table Entityset too -

Image may be NSFW.
Clik here to view.
Getter.jpg

Now the metadata should look like below

 

<edmx:Edmxxmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:sap="http://www.sap.com/Protocols/SAPData"Version="1.0">

 

 

 

 

 

<edmx:DataServicesm:DataServiceVersion="2.0">

 

 

<Schemaxmlns="http://schemas.microsoft.com/ado/2008/09/edm"Namespace="ZSMARTTABLE4"xml:lang="en"sap:schema-version="0000">

 

 

<EntityTypeName="SmartTable"sap:content-version="1">

 

 

<Key>

 

 

<PropertyRefName="Bname"/>

 

</Key>

<PropertyName="Bname"Type="Edm.String"Nullable="false"MaxLength="12"sap:label="User"/>

<PropertyName="Fullname"Type="Edm.String"Nullable="false"MaxLength="80"sap:label="Complete name"/>

<PropertyName="SmtpAddr"Type="Edm.String"Nullable="false"MaxLength="241"sap:label="E-Mail Address"/>

<PropertyName="Location"Type="Edm.String"Nullable="false"MaxLength="40"sap:label="Location"/>

</EntityType>

 

<EntityContainerName="ZSMARTTABLE4_Entities"m:IsDefaultEntityContainer="true">

 

 

<EntitySetName="SmartTableSet"EntityType="ZSMARTTABLE4.SmartTable"sap:content-version="1"/>

 

</EntityContainer>

 

<Annotationsxmlns="http://docs.oasis-open.org/odata/ns/edm"Target="SmartTable">

 

 

<AnnotationTerm="com.sap.vocabularies.UI.v1.LineItem">

 

 

<Collection>

 

 

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation">

 

 

<PropertyValueProperty="Label"String="Location"/>

 

<PropertyValueProperty="Target"AnnotationPath="Location"/>

</Record>

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation"/>

 

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation">

 

 

<PropertyValueProperty="Label"String="Location"/>

 

<PropertyValueProperty="Target"AnnotationPath="Location"/>

</Record>

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation"/>

</Collection>

</Annotation>

</Annotations>

<atom:linkxmlns:atom="http://www.w3.org/2005/Atom"rel="self"href="<host:port>/sap/opu/odata/sap/ZSMARTTABLE4/$metadata"/>

<atom:linkxmlns:atom="http://www.w3.org/2005/Atom"rel="latest-version"href="<host:port>/sap/opu/odata/sap/ZSMARTTABLE4/$metadata"/>

</Schema>

</edmx:DataServices>

</edmx:Edmx>


Front End Code


Step 13: For sake of simplicity I have put the Smart Table in Index.html file and run it.


<!DOCTYPE html>

<html><head>

  <meta http-equiv='X-UA-Compatible' content='IE=edge' />

  <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

  <title>Smart Table</title>

 

  <script id='sap-ui-bootstrap' type='text/javascript'

  src='/sapui5/resources/sap-ui-core.js'

  data-sap-ui-theme='sap_bluecrystal'

  data-sap-ui-xx-bindingSyntax="complex"

  data-sap-ui-libs='sap.ui.commons, sap.m'>

  </script>

 

  <script id="view1" type="sapui5/xmlview">

  <core:View xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable" controllerName="smartTable.controller" class="sapUiSizeCompact">

  <Page id="page" title="Customers">

 

  <smartTable:SmartTable entitySet="SmartTableSet"  enableAutoBinding="true"/>

  </Page>

  </core:View>

  </script>

 

  <script>

  //Controller

  sap.ui.controller("smartTable.controller", {

  onInit: function() {

  var sURL, oModel, oView;

 

  sURL = "<host:port>/sap/opu/odata/sap/ZSMARTTABLE4";

  oModel = new sap.ui.model.odata.v2.ODataModel(sURL, {

  json: true

  });

  oView = this.getView();

  oView.setModel(oModel);

  }

  });

 

  jQuery.sap.declare("smartTable.Component");

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

  /**

  * Initialize the application

  *

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

  */

  createContent: function() {

  var app = new sap.m.App({

  initialPage: "idView"

  });

  var oView = sap.ui.xmlview("idView", { viewContent: jQuery("#view1").html() });         

  app.addPage(oView);

  return app;

  }

  });

 

  new sap.ui.core.ComponentContainer({

  name : "smartTable"

  }).placeAt("content")

 

  </script>

 

  </head>

  <body class='sapUiBody'>

  <div id='content'></div>

  </body>

</html>

 

 

Final Output -

 

Image may be NSFW.
Clik here to view.
Output.jpg

 

PS: You may get some errors like one shown below but it is dependent on the SAPUI5 Version. I have used 1.33.0-SNAPSHOT version but it works on 1.28 also.

 

Image may be NSFW.
Clik here to view.
Error.jpg

 

 

I would like to thank Santhosh Gowda whose blog gave me inspiration to test this control and Arshdeep Singh for his help.

 

I would request you all to provide feedback and ask questions to enhance everyone's learning.

 

BR,

Ankit Maskara.


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>